mql5

Stochastic buffer buy n sell


i am try to get a stochastic buffer for an EA to take a sell position position crossing below the 20period and take a buy position crossing above the 20 period

if(cntBuy==0 && bufferMain[0]<=(100-InpUpperLevel) && bufferMain[1]>(100-InpUpperLevel)) expecting this to take a buy position crossing above the 20 period (21)

if(cntSell==0 && bufferMain[0]>=InpUpperLevel && bufferMain[1]<InpUpperLevel) expecting this to take a sell position crossing below the 80period (79)


Solution

  • You've not got the logic correct for what you want to do. Try

    int InpUpperLevel=80;

    Buy: if(cntBuy==0 && bufferMain[0]>(100-InpUpperLevel) && bufferMain[1]<=(100-InpUpperLevel))

    Sell: if(cntSell==0 && bufferMain[0]<InpUpperLevel && bufferMain[1]>=InpUpperLevel)