| / | Forum |
|
SanMiguel
2009.07.01 14:51
I'm getting order modify errors on this, not sure why - any ideas? //steppedtrail int FirstTP = 10; int SecondTP = 25; int ThirdTP = 50; int FourthTP = 100; int FifthTP = 200; int SixthTP = 300; if (usingsteppedTrail==true) {TradeTargetPrice=SixthTP;} if (usingsteppedTrail==true) { int totaltoStep = OrdersTotal(); for(int itoStep=totaltoStep-1;itoStep>=0;itoStep--) { if( OrderSelect(itoBE,SELECT_BY_POS) && OrderCloseTime()==0 ) { if( ( OrderType()==OP_BUY ) && (OrderMagicNumber() == EA_ID) && ((Bid-OrderOpenPrice()) >= Point*FifthTP)) {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*FourthTP,OrderTakeProfit(),0);} else if( ( OrderType()==OP_BUY ) && (OrderMagicNumber() == EA_ID) && ((Bid-OrderOpenPrice()) >= Point*FourthTP)) {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*ThirdTP,OrderTakeProfit(),0);} else if( ( OrderType()==OP_BUY ) && (OrderMagicNumber() == EA_ID) && ((Bid-OrderOpenPrice()) >= Point*ThirdTP)) {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*SecondTP,OrderTakeProfit(),0);} else if( ( OrderType()==OP_BUY ) && (OrderMagicNumber() == EA_ID) && ((Bid-OrderOpenPrice()) >= Point*SecondTP)) {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*FirstTP,OrderTakeProfit(),0);} else if( ( OrderType()==OP_BUY ) && (OrderMagicNumber() == EA_ID) && ((Bid-OrderOpenPrice()) >= Point*FirstTP)) {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);} else if( ( OrderType()==OP_SELL ) && (OrderMagicNumber() == EA_ID) && ((OrderOpenPrice()-Ask) > Point*FifthTP)) {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*FourthTP,OrderTakeProfit(),0);} else if( ( OrderType()==OP_SELL ) && (OrderMagicNumber() == EA_ID) && ((OrderOpenPrice()-Ask) > Point*FourthTP)) {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*ThirdTP,OrderTakeProfit(),0);} else if( ( OrderType()==OP_SELL ) && (OrderMagicNumber() == EA_ID) && ((OrderOpenPrice()-Ask) > Point*ThirdTP)) {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*SecondTP,OrderTakeProfit(),0);} else if( ( OrderType()==OP_SELL ) && (OrderMagicNumber() == EA_ID) && ((OrderOpenPrice()-Ask) > Point*SecondTP)) {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*FirstTP,OrderTakeProfit(),0);} else if( ( OrderType()==OP_SELL ) && (OrderMagicNumber() == EA_ID) && ((OrderOpenPrice()-Ask) > Point*FirstTP)) {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);} } } } |
|
The main limitation for automated trading systems is the fact that they are only efficient under certain conditions on the markets. |
|
SanMiguel
2009.07.02 15:48
Any ideas? |
|
robofx.org
2009.07.02 16:15
What is that itoBE variable? if( OrderSelect(itoBE,SELECT_BY_POS) && OrderCloseTime()==0 ) I think it should be itoStep.. |
|
SanMiguel
2009.07.02 17:46
Yes, of course - thanks. Am I right in thinking the if else statements will only execute 1 of those statements and if 1 is true it skips all the rest? I can't seem to find any trades in the strategy tester at more than FirstTP |
|
robofx.org
2009.07.02 18:02
Suppose that (Bid-OrderOpenPrice()) >= Point*FifthTP) is true. Then all the other conditions will be true too: (Bid-OrderOpenPrice()) >= Point*FourfthTP) will be true, (Bid-OrderOpenPrice()) >= Point*ThirdTP) will be true and so on. So you finally end modifying the order with FirstTP. |
|
SanMiguel
2009.07.02 19:13
robofx.org wrote >>
Suppose that (Bid-OrderOpenPrice()) >= Point*FifthTP) is true. Then all the other conditions will be true too: (Bid-OrderOpenPrice()) >= Point*FourfthTP) will be true, (Bid-OrderOpenPrice()) >= Point*ThirdTP) will be true and so on. So you finally end modifying the order with FirstTP. but the else if should ignore that shouldn't it? if do this else do that if the first is true it doesn't go onto the else... |
|
robofx.org
2009.07.02 19:58
SanMiguel wrote >>
but the else if should ignore that shouldn't it? if do this else do that if the first is true it doesn't go onto the else... Nope, the else if will not ignore the other checks. If it was if-else it would ignore the rest but not in your case with if-else if. In your case if the first if is true then all other if's are also true and will be executed. So try to check the conditions in reverse order. First check FirstTP, SecondTP, ThirdTP and so on.. |
|
SanMiguel
2009.07.02 20:20
robofx.org wrote >>
Nope, the else if will not ignore the other checks. If it was if-else it would ignore the rest but not in your case with if-else if. In your case if the first if is true then all other if's are also true and will be executed. So try to check the conditions in reverse order. First check FirstTP, SecondTP, ThirdTP and so on.. Hmm, that's strange :) I thought in most programming languages the ElseIf (as in VB) the else was part of the 1st if statement. In which case why do we use the else statement at all? Why not just: if this if this if this if this also if I swap them round then it will change the stop loss on every tick. What about this: if (OrderType()==OP_BUY && OrderMagicNumber() == EA_ID) { if((Bid-OrderOpenPrice()) >= Point*FifthTP) {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*FourthTP,OrderTakeProfit(),0);} else { if((Bid-OrderOpenPrice()) >= Point*FourthTP) {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*ThirdTP,OrderTakeProfit(),0);} else { if((Bid-OrderOpenPrice()) >= Point*ThirdTP) {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*SecondTP,OrderTakeProfit(),0);} else { if((Bid-OrderOpenPrice()) >= Point*SecondTP) {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*FirstTP,OrderTakeProfit(),0);} else { if((Bid-OrderOpenPrice()) >= Point*FirstTP) {OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);} } } } } } |
|
robofx.org
2009.07.02 23:12
SanMiguel wrote >>
Hmm, that's strange :) I thought in most programming languages the ElseIf (as in VB) the else was part of the 1st if statement. In which case why do we use the else statement at all? Why not just: if this if this if this if this also if I swap them round then it will change the stop loss on every tick. What about this: Yup, now it's different and looks good to me. |
|
SanMiguel
2009.07.02 23:23
Next problem :) It seems to change the price back and forth between the values so that a stop is never actually hit until the zero stop. Wouldn't the stop be hit first before the tick value changes the stop back to the next level below? Maybe the >= part and the stop isn't hit until it moves past that point? |
|
robofx.org
2009.07.02 23:30
SanMiguel wrote >>
Next problem :) It seems to change the price back and forth between the values so that a stop is never actually hit until the zero stop. Wouldn't the stop be hit first before the tick value changes the stop back to the next level below? I'm sorry but didn't get what the problem is. What is that zero stop ? What exactly are you trying to accomplish? |