Ask! - page 29

 
Yannis:
Dave,

Try changing your code to following snippet and let me know if that did the trick.

Yannis

int i=0;

for (int cnt=OrdersTotal()-1;cnt>=0;cnt--)

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if (OrderType()>=OP_SELL && OrderSymbol()==Symbol() && (OrderMagicNumber () == MagicNumber || MagicNumber==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(15 *Point),Bid-(20*Point),Cyan); //Modify stop loss and take profit

return(0);

}

if (OrderType()>=OP_BUY && OrderSymbol()==Symbol() && (OrderMagicNumber () == MagicNumber || MagicNumber==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(15*Point),Ask+(20*Point),Cyan); //Modify stop loss and take profit

return(0);

}

return(0);

}

}

I have a problem with it always modifing the trades in the backtester over and over. How do I get it to modify the trades once. Since the program is going to sleep, the only trades that need to be modified are any trades still open.

Please see attached .Gif of Backtest results. I am so close to getting this right - Please advise!! I use this Take Profit and Stop Loss modification in conjunction with the sleep mode. Please see code below

int start()

{

if (UseHourTrade)

{

int a=0;

int b=0;

int c=0;

if(!(Hour()>=FromHourTrade1 && Hour()<=ToHourTrade1)) a=1;

if(!(Hour()>=FromHourTrade2 && Hour()<=ToHourTrade2)) b=1;

if(!(Hour()>=FromHourTrade3 && Hour()<=ToHourTrade3)) c=1;

if(a==1 && b==1 && c==1)

{

Comment(

"\n"," * SOLAR WIND EXPERT ADVISOR *",

"\n",

"\n", " - PROGRAM IN SLEEP CYCLE - ",

"\n",

"\n"," > NON-TRADING HOURS! <");

///////////////////MODIFY STOP LOSS & TAKE PROFIT AT START OF SLEEP CYCLE /////////////////

int h=0;

for (int cnt1=OrdersTotal()-1;cnt1>=0;cnt1--)

OrderSelect(h, SELECT_BY_POS, MODE_TRADES);

if (OrderType()>=OP_SELL && OrderSymbol()==Symbol() && (OrderMagicNumber () == MagicNumber || MagicNumber==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(15 *Point),Bid-(20*Point),Cyan); //Modify stop loss and take profit

return(0);

}

if (OrderType()>=OP_BUY && OrderSymbol()==Symbol() && (OrderMagicNumber () == MagicNumber || MagicNumber==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(15*Point),Ask+(20*Point),Cyan); //Modify stop loss and take profit

return(0);

}

return(0);

}

}

Dave <<<

PLEASE LOOK AT ATTACHED THUMBNAIL!

 

for (int cnt1=OrdersTotal()-1;cnt1>=0;cnt1--)

OrderSelect(cnt1, SELECT_BY_POS, MODE_TRADES);

make it counts the same number

 

Do not understand. How do I correct this error?? Maybe I do see - Let me change cnt1 to h. Am I correct?

Dave

<<

 
phoenix:
your OrderSelect() did not count base on the running loop

int start()

{

if (UseHourTrade)

{

int a=0;

int b=0;

int c=0;

if(!(Hour()>=FromHourTrade1 && Hour()<=ToHourTrade1)) a=1;

if(!(Hour()>=FromHourTrade2 && Hour()<=ToHourTrade2)) b=1;

if(!(Hour()>=FromHourTrade3 && Hour()<=ToHourTrade3)) c=1;

if(a==1 && b==1 && c==1)

{

Comment(

"\n"," * SOLAR WIND EXPERT ADVISOR *",

"\n",

"\n", " - PROGRAM IN SLEEP CYCLE - ",

"\n",

"\n"," > NON-TRADING HOURS! <");

///////////////////MODIFY STOP LOSS & TAKE PROFIT AT START OF SLEEP CYCLE /////////////////

//int h=0;

for (int h=OrdersTotal()-1;h>=0;h--)

OrderSelect(h, SELECT_BY_POS, MODE_TRADES);

if (OrderType()>=OP_SELL && OrderSymbol()==Symbol() && (OrderMagicNumber () == MagicNumber || MagicNumber==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(15 *Point),Bid-(20*Point),Cyan); //Modify stop loss and take profit

return(0);

}

if (OrderType()>=OP_BUY && OrderSymbol()==Symbol() && (OrderMagicNumber () == MagicNumber || MagicNumber==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(15*Point),Ask+(20*Point),Cyan); //Modify stop loss and take profit

return(0);

}

return(0);

}

}

///////////////////////////////////////////////////////////////////////////////////////

Made the changes but still getting a constant loop of modifications versus a one time change.

Please advise again, please!

Dave

<<<

 

Please post your code within the [PHP][/PHP] codes. It is much easier to read and debug formatted code.

 

Indicator Input Tab

How and where do I code an indicator so that the Input Tab no longer show when it is attached to the chart?

Thanks,

solaris

 
iscuba11:
int start()

{

if (UseHourTrade)

{

int a=0;

int b=0;

int c=0;

if(!(Hour()>=FromHourTrade1 && Hour()<=ToHourTrade1)) a=1;

if(!(Hour()>=FromHourTrade2 && Hour()<=ToHourTrade2)) b=1;

if(!(Hour()>=FromHourTrade3 && Hour()<=ToHourTrade3)) c=1;

if(a==1 && b==1 && c==1)

{

Comment(

"\n"," * SOLAR WIND EXPERT ADVISOR *",

"\n",

"\n", " - PROGRAM IN SLEEP CYCLE - ",

"\n",

"\n"," > NON-TRADING HOURS! <");

///////////////////MODIFY STOP LOSS & TAKE PROFIT AT START OF SLEEP CYCLE /////////////////

//int h=0;

for (int h=OrdersTotal()-1;h>=0;h--)

OrderSelect(h, SELECT_BY_POS, MODE_TRADES);

if (OrderType()>=OP_SELL && OrderSymbol()==Symbol() && (OrderMagicNumber () == MagicNumber || MagicNumber==0))

{if( OrderStopLoss() > Ask + Point * 15 || OrderStopLoss() == 0 )

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(15 *Point),Bid-(20*Point),Cyan); //Modify stop loss and take profit

return(0);

}

if (OrderType()>=OP_BUY && OrderSymbol()==Symbol() && (OrderMagicNumber () == MagicNumber || MagicNumber==0))

{

if( OrderStopLoss() < Bid - Point * 15 )

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(15*Point),Ask+(20*Point),Cyan); //Modify stop loss and take profit

return(0);

}

return(0);

}

}

///////////////////////////////////////////////////////////////////////////////////////

Made the changes but still getting a constant loop of modifications versus a one time change.

Please advise again, please!

Dave

<<<

try add the purple line ..may help

 
solaris:
How and where do I code an indicator so that the Input Tab no longer show when it is attached to the chart?

Thanks,

solaris

why don't try save it as a template instead...then there's no need to setup any parameters again when you call all your indicators into new chart

 

I have done as you suggested! (I appreciate your patience)

for (int cnt1=OrdersTotal()-1;cnt1>=0;cnt1--)

OrderSelect(cnt1, SELECT_BY_POS, MODE_TRADES);

** But I am still getting massive loop modifications on a single trade like before!

I evidently have a loop within a loop in the logic!

Dave

<<

Please see latest backtest results. Excuse the logo.htm - Can't get rid of it.

 
iscuba11:
I have done as you suggested! (I appreciate your patience)

for (int cnt1=OrdersTotal()-1;cnt1>=0;cnt1--)

OrderSelect(cnt1, SELECT_BY_POS, MODE_TRADES);

** But I am still getting massive loop modifications on a single trade like before!

I evidently have a loop within a loop in the logic!

Dave

<<
Please see latest backtest results. Excuse the logo.htm - Can't get rid of it.

try adding the purple above yet?

theif( OrderStopLoss() > Ask + Point * 15 || OrderStopLoss() == 0 )

and if( OrderStopLoss() < Bid - Point * 15 )