Help! - How do I hedge with the total of the opposite direction?

 

Help! - How do I hedge with the total of the opposite direction?

Scenario: I have a couple of opened short positions, then price break the resistance.

I would like to take a long position which is the maybe twice the TotalShortPosition() - (which is a function that calculate the total short positions.)

Thanks!


if ( (Ask > resistance) && (asks[0] <= resistance) )

1) I tried to do a golden cross, ask[0] is the previous ask price but condition does not work??? It does not meet.


if (Ask > resistance)

only is used, many orders are placed not just the 1 order I intended.


void BreakResistance()
{

if (OrderSelect(1, SELECT_BY_POS, MODE_TRADES))
{
double resistance = OrderOpenPrice()+(Resistance*Point*10);
{

if ( (Ask > resistance) && (asks[0] <= resistance) )
{
int BuyLot = TotalShortPositions()*2;
int ticket1=OrderSend(Symbol(),OP_BUY,BuyLot,Ask,3,0,0,"My EA",12345,0,Red);
return(0);
}
}
}
}

 

Hi Johnny

My comments, for what they're worth:

1. Your condition involving ask[0] may not be working because you use asks[0] - note the spelling.

2. The condition: if (Ask > resistance) will trigger on every tick if the Ask is above the value of resistance because it is true on every tick, hence your many orders.

3. Even the condition: if ( (Ask > resistance) && (asks[0] <= resistance) ) will trigger more than once if the price fluctuates above and below resistance, so I suggest adding a boolean variable to indicate when the hedge order is successful and test it in the condition, for example,

...
// declared outside start() for global scope
bool Hedged = False;
...
if( ( Ask > resistance ) && !Hedged )
{
   ...
   int BuyLot = TotalShortPositions()*2;
   int ticket1=OrderSend(Symbol(),OP_BUY,BuyLot,Ask,3,0,0,"My EA",12345,0,Red);
   if( ticket1 > 0 )   // order was successful
      Hedged = True;
   return(0);
}

Hope this helps.

Cheers

Jellybean

Reason: