-
for(a;a<1;a++) for(a2;a2<2;a2++) for(a3;a3<4;a3++)//<-will not trigger.
What do you think "a;", "a2;", and "a3;" do? They are not valid statements.
-
Do you think CountTrades() and CountPenOrders() ever return different values?
-
What do you think "a;", "a2;", and "a3;" do? They are not valid statements.
-
Do you think CountTrades() and CountPenOrders() ever return different values?
The "a", "a2 " & "a3" were used for looping my account balance figure.
As for the CountTrades() and CountPenOrders() yes they do return different values. Unless you see something wrong with it?
OHHHHHH!!! My bad. I sorted it out but for 2 figures & 5 figures it opens 3 orders & 3 pending orders. For 7 figures it opens correctly.
int CountPenOrders() { int CountPending=0; for(int b=OrdersTotal()-1;b>=0;b--) { if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) if(OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP) CountPending++; } return(CountPending); }
if(TickSize==0.00001||0.001)
I'm still getting 3 orders & 3 pending orders for 2 figures & 5 figures. With 7 figures everything is correct. Here is the full code but i reverted back to the loops instead of the array's.
#property copyright "Copyright 2021, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict extern int MagicNumber=01; int MaxTrades=0; int MaxTrades2=0; int MaxTrades3=0; int MaxTrades4=0; //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ int CountTrades() { int Count=0; for(int a=OrdersTotal()-1;a>=0;a--) { if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) if(OrderType()==OP_BUY||OrderType()==OP_SELL) Count++; } return(Count); } int CountPenOrders() { int Pending=0; for(int b=OrdersTotal()-1;b>=0;b--) { if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) if(OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP) Pending++; } return(Pending); } void Buy() { double TwoFigures=AccountBalance()>10; double FiveFigures=AccountBalance()>10000; double SevenFigures=AccountBalance()>1000000; int a=0==TwoFigures; int a2=0==FiveFigures; int a3=0==SevenFigures; double Trades[3]; int AccTrades=3; Trades[0]=TwoFigures; Trades[1]=FiveFigures; Trades[2]=SevenFigures; double PSAR=iSAR(Symbol(),NULL,0.02,0.2,0); if(MaxTrades!=1) { if(PSAR<Bid) { MaxTrades=1; for(a;a<1;a++) for(a2;a2<2;a2++) for(a3;a3<4;a3++) //for(int i=0;i<=AccTrades-1;i++) { int BuyTrade=OrderSend(Symbol(),OP_BUY,0.01,Ask,0,0,0,"JackBuda",MagicNumber,0,clrBlue); } } } } void BuyInProfit() { double Pips=0; double TickSize=MarketInfo(Symbol(),MODE_TICKSIZE); if(TickSize==0.00001||TickSize==0.001) Pips=TickSize*10; else Pips=TickSize; double TwoFigures=AccountBalance()>10; double FiveFigures=AccountBalance()>10000; double SevenFigures=AccountBalance()>1000000; int b=0==TwoFigures; int b2=0==FiveFigures; int b3=0==SevenFigures; double Trades[3]; int AccTrades=3; Trades[0]=TwoFigures; Trades[1]=FiveFigures; Trades[2]=SevenFigures; double PSAR=iSAR(Symbol(),NULL,0.02,0.2,0); if(MaxTrades2!=1) { if(PSAR<Bid) { MaxTrades2=1; for(b;b<1;b++) for(b2;b2<2;b2++) for(b3;b3<4;b3++) //for(int i=0;i<=AccTrades-1;i++) { int BuyTrade=OrderSend(Symbol(),OP_BUYSTOP,0.01,Ask+(5*Pips),0,0,0,"JackBuda",MagicNumber,0,clrBlue); } } } } void BuyInProfit2() { double Pips=0; double TickSize=MarketInfo(Symbol(),MODE_TICKSIZE); if(TickSize==0.00001||TickSize==0.001) Pips=TickSize*10; else Pips=TickSize; double TwoFigures=AccountBalance()>10; double FiveFigures=AccountBalance()>10000; double SevenFigures=AccountBalance()>1000000; int c=0==TwoFigures; int c2=0==FiveFigures; int c3=0==SevenFigures; double Trades[3]; int AccTrades=3; Trades[0]=TwoFigures; Trades[1]=FiveFigures; Trades[2]=SevenFigures; double PSAR=iSAR(Symbol(),NULL,0.02,0.2,0); if(MaxTrades3!=1) { if(PSAR<Bid) { MaxTrades3=1; for(c;c<1;c++) for(c2;c2<2;c2++) for(c3;c3<4;c3++) //for(int i=0;i<=AccTrades-1;i++) { int BuyTrade=OrderSend(Symbol(),OP_BUYSTOP,0.01,Ask+(12*Pips),0,0,0,"JackBuda",MagicNumber,0,clrBlue); } } } } void Sell() { double Pips=0; double TickSize=MarketInfo(Symbol(),MODE_TICKSIZE); if(TickSize==0.00001||TickSize==0.001) Pips=TickSize*10; else Pips=TickSize; double TwoFigures=AccountBalance()>10; double FiveFigures=AccountBalance()>10000; double SevenFigures=AccountBalance()>1000000; int a=0==TwoFigures; int a2=0==FiveFigures; int a3=0==SevenFigures; double Trades[3]; int AccTrades=3; Trades[0]=TwoFigures; Trades[1]=FiveFigures; Trades[2]=SevenFigures; double PSAR=iSAR(Symbol(),NULL,0.02,0.2,0); if(MaxTrades!=-1) { if(PSAR>Ask) { MaxTrades=-1; for(a;a<1;a++) for(a2;a2<2;a2++) for(a3;a3<4;a3++) //for(int i=0;i<=AccTrades-1;i++) { int SellTrade=OrderSend(Symbol(),OP_SELL,0.01,Bid,0,0,0,"JackBuda",MagicNumber,0,clrRed); } } } } void SellInProfit() { double Pips=0; double TickSize=MarketInfo(Symbol(),MODE_TICKSIZE); if(TickSize==0.00001||TickSize==0.001) Pips=TickSize*10; else Pips=TickSize; double TwoFigures=AccountBalance()>10; double FiveFigures=AccountBalance()>10000; double SevenFigures=AccountBalance()>1000000; int b=0==TwoFigures; int b2=0==FiveFigures; int b3=0==SevenFigures; double Trades[3]; int AccTrades=3; Trades[0]=TwoFigures; Trades[1]=FiveFigures; Trades[2]=SevenFigures; double PSAR=iSAR(Symbol(),NULL,0.02,0.2,0); if(MaxTrades2!=-1) { if(PSAR>Ask) { MaxTrades2=-1; for(b;b<1;b++) for(b2;b2<2;b2++) for(b3;b3<4;b3++) //for(int i=0;i<=AccTrades-1;i++) { int SellTrade=OrderSend(Symbol(),OP_SELLSTOP,0.01,Bid-(5*Pips),0,0,0,"JackBuda",MagicNumber,0,clrRed); } } } } void SellInProfit2() { double Pips=0; double TickSize=MarketInfo(Symbol(),MODE_TICKSIZE); if(TickSize==0.00001||TickSize==0.001) Pips=TickSize*10; else Pips=TickSize; double TwoFigures=AccountBalance()>10; double FiveFigures=AccountBalance()>10000; double SevenFigures=AccountBalance()>1000000; int c=0==TwoFigures; int c2=0==FiveFigures; int c3=0==SevenFigures; double Trades[3]; int AccTrades=3; Trades[0]=TwoFigures; Trades[1]=FiveFigures; Trades[2]=SevenFigures; double PSAR=iSAR(Symbol(),NULL,0.02,0.2,0); if(MaxTrades3!=-1) { if(PSAR>Ask) { MaxTrades3=-1; for(c;c<1;c++) for(c2;c2<2;c2++) for(c3;c3<4;c3++) //for(int i=0;i<=AccTrades-1;i++) { int SellTrade=OrderSend(Symbol(),OP_SELLSTOP,0.01,Bid-(10*Pips),0,0,0,"JackBuda",MagicNumber,0,clrRed); } } } } void OnTick() { double TwoFigures=AccountBalance()>10; double FiveFigures=AccountBalance()>10000; double SevenFigures=AccountBalance()>1000000; if(TwoFigures) { if(AccountBalance()>10&&CountTrades()<1){Buy();} else if(CountPenOrders()<2){BuyInProfit();} else if(CountPenOrders()<3){BuyInProfit2();} if(AccountBalance()>10&&CountTrades()<1){Sell();} else if(CountPenOrders()<2){SellInProfit();} else if(CountPenOrders()<3){SellInProfit2();} } if(FiveFigures) { if(AccountBalance()>10000&&CountTrades()<2){Buy();} else if(CountPenOrders()<4){BuyInProfit();} else if(CountPenOrders()<6){BuyInProfit2();} if(AccountBalance()>10000&&CountTrades()<2){Sell();} else if(CountPenOrders()<4){SellInProfit();} else if(CountPenOrders()<6){SellInProfit2();} } if(SevenFigures) { if(AccountBalance()>1000000&&CountTrades()<4){Buy();} else if(CountPenOrders()<8){BuyInProfit();} else if(CountPenOrders()<12){BuyInProfit2();} if(AccountBalance()>1000000&&CountTrades()<4){Sell();} else if(CountPenOrders()<8){SellInProfit();} else if(CountPenOrders()<12){SellInProfit2();} } for(int Loop2=OrdersTotal()-1;Loop2>=0;Loop2--) { if(OrderSelect(Loop2,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) { bool CloseTrade=false; int Type=OrderType(); double Profit=OrderLots()*150; switch(Type) { case OP_BUY:if(OrderProfit()>=Profit)CloseTrade=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,clrGreen);break; case OP_SELL:if(OrderProfit()>=Profit)CloseTrade=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,clrGreen);break; //Print("ErrorCode:",GetLastError()); } } } }
int c=0==TwoFigures; int c2=0==FiveFigures; int c3=0==SevenFigures;

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
The third for loop will not trigger. So i decided to use arrays, which not have worked as I would've wanted to. In the case it will open 3 trades for 2 figures, 5 figures & 7 figure.
If there's way to open the 3rd for loop with/without arrays, please let me know how to.