This loop, in the code named CheckForSignal() es used to get the singal for open or close a trade.
The loop return the value of two bools, signalBuy and signalSell.
The result of this bools will be used to open or close positions.
Let going to see the example of the Expert Advisor CyberEA-Template.
In the template if
signalBuy=true is a buy signal and if signalSell=true is a sell signal.CyberEA gets the value of slowMA (Slow MA) and fastMA (Fast MA) and if
fastMA>slowMA return signalBuy=true so, a buy signal.This value will be called from check for open and check for close loops, wich we will see in other post, to take action.
Note that the settings of MA are selected from external variables that can be changed after compilation of the code.
void BuscarSenal()
{
if (time_now != Time[0])
{
time_now = Time[0];
slowMA = iMA(NULL,0,SlowMAPeriod,SlowMAShift,SlowMAMode,SlowMAApplyPrice,Bar);
fastMA = iMA(NULL,0,FastMAPeriod,FastMAShift,FastMAMode,FastMAApplyPrice,Bar);
}
signalSell = false;
signalBuy = false;
if (fastMA>slowMA) signalBuy = true;
if (slowMA>fastMA) signalSell=true;
goLong = signalBuy;
goShort = signalSell;
if (goLong || goShort) return;
if (BuscarOrdenes() != 0)
{
goLong = false;
goShort = false;
}
}
1 coments:
November 10, 2011 at 9:46 AM
Hello,
Is there any way more that one buy or sell can be done without closing the previous one. I mean, lest say it opens, and opens, and opens and then it closes all?
Thanks.
Samuel
Post a Comment