How to code? - page 120

 
denis68:
matrixebiz what do you mean by rem'ing out these two lines; and how do i do it, i can;t get in to the code of the AC indicator i have tried,

You open up Accelerator.mq4 in MetaEditor (it's in your Indicators folder) and put // in front of those two lines then save as a new name AcceleratorMod.mq4 then click compile.

Files:
 
hiachiever:
No that isn't correct.

In the for loop you are starting at 6 and decrementing to 1. This means in the final loop the for loop executes it carries out the "if (i == 1) qqeacross = True;" check. End result is that the output will be true if qqeacross has occurred.

The only problem that this may present is if qqeacross was set to true in a previous looop. To overcome this you should have qqeacross = false; prior to the for loop. In this way you can ensure that if qqeacross = true, then it was set by the loop just completed.

Cheers,

hiachiever

So even if it says "if (i == 1) qqeacross = True;" and then i=4 (because of the countdown) , qqeacross will still = True?

 

Thanks hiachiever!

hiachiever:
The way to do it is create a vriable on global scope (ie before init)

eg

int BarCount;

int init ()

Then in your stop loss code use the following:

if (BarCount<Bars)

{

SL=iLow(Symbol(),Period(),iLowest(Symbol(),Period(),MODE_LOW,StopLossBars,0));

StopLossBars++;

BarCount=Bars;

}

This will increment StopLossBars by 1 on each new bar.

The only other addition to your code would be to reset 'StopLossBars' back its original default value when a new trade is opened.

Cheers,

Hiachiever

Thankyou, hiachiever, it was very kind of you to help although I would like to ask one other small favour please.

I think that I understand how your piece of code works and I'm sure that I can copy it into my EA . I'm not sure how to reset the StopLossBars back to their default though. This is the code at the end of the EA for going long or short:

void goLong()

{

int ticket = OrderSend(Symbol(),OP_BUY,GetLots(100),Ask,maxSlippage,0,0,"Long",MagicNumber,0,Green);

if (screenshots) WindowScreenShot(Symbol()+Period()+"_"+Hour()+Minute()+"_.gif",1024,768);

if (showAlerts) Alert(Symbol()+" "+Period()+" TrendLevel at "+DoubleToStr(Level,0)+": Going Long");

Print(Symbol()+" "+Period()+" TrendLevel at "+DoubleToStr(Level,0)+": Going Long");

}

void goShort()

{

int ticket = OrderSend(Symbol(),OP_SELL,GetLots(100),Bid,maxSlippage,0,0,"Short",MagicNumber,0,Red);

if (screenshots) WindowScreenShot(Symbol()+Period()+"_"+Hour()+Minute()+"_.gif",1024,768);

if (showAlerts) Alert(Symbol()+" "+Period()+" TrendLevel at "+DoubleToStr(Level,0)+": Going Short");

Print(Symbol()+" "+Period()+" TrendLevel at "+DoubleToStr(Level,0)+": Going Short");

}

double stopLoss(int ordertype)

Could you be so kind as to help with some code to reset the StopLossBars please?

Thanks again.

 

matrixebiz i have done that now i can't compile my ea when i added the following lines to my ea

double ac1 = iCustom(NULL, 0, "AcceleratorMod", 1, 1);

double ac2 = iCustom(NULL, 0, "AcceleratorMod", 2, 1);

double ac11 = iCustom(NULL, 0, "AcceleratorMod", 1, 2);

double ac22 = iCustom(NULL, 0, "AcceleratorMod", 2, 2);

bool acbuy = ac2==0 && ac11==0; // Red changes to Lime

bool acsell = ac1==0 && ac22==0; // Lime changes to Red

i get 12 errors: AC variable not defined :

and i would like to thank you for the help

 

I assume StopLossBars is a global variable that is set via the user inputs right?

Well what I'd do is something like this.

Have the user input variable be something like gStopLossBars then in your init function assign it to your local variable like...

StopLossBars = gStopLossBars;

Then simply use the same assignment in your buy and sell functions to reset StopLossBars.

Make sense?

Hope that helps.

Lux

 

Ac+ao+psar

Hi all,

Anyone can combine AC+AO+PSAR to become a new indicator with alert/email? Please PM me. Thank you

 
luxinterior:
I assume StopLossBars is a global variable that is set via the user inputs right?

Well what I'd do is something like this.

Have the user input variable be something like gStopLossBars then in your init function assign it to your local variable like...

StopLossBars = gStopLossBars;

Then simply use the same assignment in your buy and sell functions to reset StopLossBars.

Make sense?

Hope that helps.

Lux

That makes perfect sense. Thanks everso much.

 

How can I detect when the new candle is start?

please someone give me some advice how can I create an EA that make a pending order when the new bar start (daily TF) ?

thanks

 
:: hi! check the code inside this indicator... (for your opening time only, it's not an EA)
tcl:
please someone give me some advice how can I create an EA that make a pending order when the new bar start (daily TF) ? thanks
 

Can anyone stop this from looping and looping?

void BEM ()

{

int pips;

for (int k=0; k<OrdersTotal ();k++)

{

OrderSelect(k, SELECT_BY_POS, MODE_TRADES);

if(OrderType()==OP_BUY && OrderSymbol()== Symbol () && OrderMagicNumber()== Magic)

{

pips = (Bid - OrderOpenPrice())/Point;

if ((pips >= BE) && (OrderStopLoss() < OrderOpenPrice()))

{

OrderModify (OrderTicket (), OrderOpenPrice (),OrderOpenPrice ()+ 12*Point, OrderTakeProfit (), 0, LightBlue);

}

}

if(OrderType()==OP_SELL && OrderSymbol()== Symbol () && OrderMagicNumber()== Magic)

{

pips = (OrderOpenPrice() - Ask)/Point;

if ((pips >= BE) && (OrderStopLoss() > OrderOpenPrice()))

{

OrderModify (OrderTicket (), OrderOpenPrice (),OrderOpenPrice ()- 12*Point, OrderTakeProfit (), 0, Pink);

}

}

}

}

Reason: