Greetings,
I am working on code for a new EA which means I'm doing a lot of "cut & paste". Apparently I'm not able to tell up from down.
The Code is intended to place a trade either Long or Short. Upon testing last night 4 of 4 positions entered Short even though 1 of them should have been Long. So, I'm trying to correct this direction.
Parts of the code are below
--------------------------------------------------------------------------
double SAR0 = iSAR(Window, 0, 0.02, 0.2, 0); // current period
// check condition to open trade
int TradeDirection=0;
if(Point>SAR0) TradeDirection=1; // long
if(Point<SAR0) TradeDirection=-1; // short
// check if trade should be opened
if (TradeDirection==1 && !OrderFind(magicno)) OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, NormalizeDouble(Bid - StopLoss*Point, Digits),
NormalizeDouble(Ask + TakeProfit*Point, Digits), "LONG", magicno, 0, CLR_NONE);
if (TradeDirection==-1 && !OrderFind(magicno)) OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, NormalizeDouble(Ask + StopLoss*Point, Digits),
NormalizeDouble(Bid - TakeProfit*Point, Digits), "SHORT", magicno, 0, CLR_NONE);
--------------------------------------------------------------------------
Perhaps the problem is my attempt to identify the "price point" ... ?
Would appreciate any comments.
Thanks,
Pip Parade
I am working on code for a new EA which means I'm doing a lot of "cut & paste". Apparently I'm not able to tell up from down.
The Code is intended to place a trade either Long or Short. Upon testing last night 4 of 4 positions entered Short even though 1 of them should have been Long. So, I'm trying to correct this direction.
Parts of the code are below
--------------------------------------------------------------------------
double SAR0 = iSAR(Window, 0, 0.02, 0.2, 0); // current period
// check condition to open trade
int TradeDirection=0;
if(Point>SAR0) TradeDirection=1; // long
if(Point<SAR0) TradeDirection=-1; // short
// check if trade should be opened
if (TradeDirection==1 && !OrderFind(magicno)) OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, NormalizeDouble(Bid - StopLoss*Point, Digits),
NormalizeDouble(Ask + TakeProfit*Point, Digits), "LONG", magicno, 0, CLR_NONE);
if (TradeDirection==-1 && !OrderFind(magicno)) OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, NormalizeDouble(Ask + StopLoss*Point, Digits),
NormalizeDouble(Bid - TakeProfit*Point, Digits), "SHORT", magicno, 0, CLR_NONE);
--------------------------------------------------------------------------
Perhaps the problem is my attempt to identify the "price point" ... ?
Would appreciate any comments.
Thanks,
Pip Parade