How to code? - page 202

 
asgard2:
Hi,

I am unable to compile it because of an unbalanced parentheses error, can anyone tell me why these are unbalanced?

Thanks

If you are getting this error then you are missing one of [ or { or (

probably somewhere in your code there is a function where you put too much of the {[(

I checked part of your code and found some errors. Try this :

if ((type == _OP_BUYSTOP) && (MayOpenDeferOrder && NextBuyStop_Order_Minutes !=0))//Time Delay for the next Buy Stop Order

{

int hstTotal=OrdersHistoryTotal();

for(i=0;i<hstTotal;i++)

{

if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) == false)

{

Print("Access to history failed ("+GetLastError()+")");

break;

}

else

{

if (OrderDelete() && (((TimeCurrent() - OrderCloseTime())/60) =< NextBuyStop_Order_Minutes) MayOpenDeferOrder = false;

}

}

Also i think last part of your code (OrderDelete) will not work, because OrderDelete functons does not check anything - it is deleting selected order. So you need to pass parameter with order ticket to it. Instead of this you can recognize deleted orders by checking theirs comments. Each deleted order will have "canceled" in it comment - you can compare result of OrderComment() function to find this.

 

Can Someone Help Me?

Hello,

I am trying to write an EA, and I need some help writing a formula.

I want the formula to calculate the different between the previous candle close (PCC1) and the close of the candle two candles back (PCC2) (I will be running this on multiple pairs). HoL=(PCC1-PCC2)

My goal is to signal a buy or sell;

bool BuySignal=false;

bool SellSignal=false;

if(HoL>0) BuySignal=true;

if(HoL<0) SellSignal=true;

Thank you for your help with this.

 

...

If you want to use multiple symbols from one instance of EA that you can use something like this :

double HoL=iClose(symbolName,0,1)-iClose(symbolName,0,2);[/php]Or to prevent some back testing surprises, a slightly more complicated code

int symbolShift1 = iBarShift(symbolName,0,Time[1]);

int symbolShift2 = iBarShift(symbolName,0,Time[2]);

double HoL = iClose(symbolName,0,symbolShift1)-iClose(symbolName,0,symbolShift2);

If you are going to use it only on symbol that your EA is attached to than this

[php]

double HoL=Close[1]-Close[2];

is enough

PS: "symbolName" should be set to Symbol of your choice.

regards

mladen

ForExTryo:
Hello,

I am trying to write an EA, and I need some help writing a formula.

I want the formula to calculate the different between the previous candle close (PCC1) and the close of the candle two candles back (PCC2) (I will be running this on multiple pairs). HoL=(PCC1-PCC2)

My goal is to signal a buy or sell;

bool BuySignal=false;

bool SellSignal=false;

if(HoL>0) BuySignal=true;

if(HoL<0) SellSignal=true;

Thank you for your help with this.
 
 

Hide TP

Replace

void OpenBuy()

{

int ticket,err;

if (!GlobalVariableCheck("InTrade")) {

GlobalVariableSet("InTrade", CurTime()); // set lock indicator

ticket = OrderSend(Symbol(),OP_BUY,lot2,Ask,1,0,Ask+TP*Poin t,"Ask-StopLoss*Point,EA Order",magic,0,Red);

GlobalVariableDel("InTrade"); // clear lock indicator

}

}

void OpenSell()

{

int ticket,err;

if (!GlobalVariableCheck("InTrade")) {

GlobalVariableSet("InTrade", CurTime()); // set lock indicator

ticket = OrderSend(Symbol(),OP_SELL,lot2,Bid,1,0,Bid-TP*Point,Bid+StopLoss*Point,"EA Order",magic,0,Red);

GlobalVariableDel("InTrade"); // clear lock indicator

}

}[/CODE]

to

[CODE]void OpenBuy()

{

int ticket,err;

if (!GlobalVariableCheck("InTrade")) {

GlobalVariableSet("InTrade", CurTime()); // set lock indicator

ticket = OrderSend(Symbol(),OP_BUY,lot2,Ask,1,0,0,"Ask-StopLoss*Point,EA Order",magic,0,Red);

GlobalVariableDel("InTrade"); // clear lock indicator

}

}

void OpenSell()

{

int ticket,err;

if (!GlobalVariableCheck("InTrade")) {

GlobalVariableSet("InTrade", CurTime()); // set lock indicator

ticket = OrderSend(Symbol(),OP_SELL,lot2,Bid,1,0,0,"EA Order",magic,0,Red);

GlobalVariableDel("InTrade"); // clear lock indicator

}

}
 

Distance between Buy Stop orders

Hi Everyone, I am trying to implement a distance between a deleted buy stop order and the next buystop order.

I have written this code which works unless the last order is something else. I am not sure how to select a deleted buystop order from the history. If someone could point me in the right direction I would really appreciated it.

thanks

// Time Delay for the next "Buy Stop" Order is deleted.

//Time Delay for the next Buy Stop Order

if ((type == _OP_BUY) && (MayOpenDeferOrder && NextBuyStop_Order_Minutes !=0))

{

total = OrdersHistoryTotal();

for(e = total - 1; e >= 0; e--)

{

OrderSelect(e, SELECT_BY_POS,MODE_HISTORY);

if(OrderSymbol() != Symbol()) continue;

{

if(((TimeCurrent() - OrderOpenTime())/60) < NextBuyStop_Order_Minutes) MayOpenDeferOrder = false;

}

}

}

 
asgard2:
Hi Everyone,

I think, that's better:

//Time Delay for the next Buy Stop Order

if ((type == _OP_BUY) && (MayOpenDeferOrder && NextBuyStop_Order_Minutes !=0))

{

total = OrdersHistoryTotal();

for(e = total - 1; e >= 0; e--)

{

OrderSelect(e, SELECT_BY_POS,MODE_HISTORY);

if(OrderSymbol() != Symbol()) continue;

if(((TimeCurrent() - OrderOpenTime())/60) < NextBuyStop_Order_Minutes) MayOpenDeferOrder = false;

break;

}

}
 
Roger09:
I think, that's better:

Hi Roger,

I am very new to coding, why do I use the "break" there? Would it automatically break when the statement is finished?

Also, any clues on how to select a deleted order from history?

thanks

 

You show us just a fragment of the code and I can guess only.

I supposed you start to check the history after the last order is closed, so you need to know time when is was closed. The most fresh closed order is in the end of the history, so you don't need to know another and "break" stop checking.

It is tons of methods to find the proper order in the history, you have type, magic number, comments etc.

 

need coder for simple EA

profitable system : min 50 pips -200 pips profits per trade

1 hour system

use only 1 indicator plus ATR (20)

simple EA with tp/sl/trailing stop

EA coder can help out free please PM with your email

Reason: