What Reasons for a Trade to Close so quickly - page 2

 

Many thanks for your suggestions but still not sure that I understand.

Fernando & Enrique

My stratedgy is quite simple:-

1. look for a high & low in the last 15 (say) bars (i.e. looking for consolidation)

2. Establish if the difference exceeds a given range (250 points on M15)

3. if within the range then look for a BREAKOUT from that range.

4. If the last completed candle closes below the LO of the range then SELL & if the candle closes above the HI of the range BUY

Sounds simple and the code is quite simple and I only require ONE open position at a time - i.e. I am not trying to hedge in any way or trying to take multiple positions

I have put FILEWRITES (in routine Report_StringError  write to file so I can analyse / check later) around the Buy & Sell coding and I only pass through one section of code OR the other - i.e. I don't BUY and then SELL thereby closing the BUY

//...........................................................................................................
      if ( ClosePrice > RangeHi )                  // i.e. Last completed bar (#1) close price > RangeHi - bars 2 - 22)
      {  if ( MTF == true ) Report_StringError("Both","100161 NBC ClosePrice > RangeHi");          // this checks _Lasterror and prints the second text string ~~ MTF is Master Test Flag
         if ( OpenTrade(buyPrice,  ORDER_TYPE_BUY)  == false) return;      // original Orange
         if ( MTF == true ) Report_StringError("Both","100162 NBC ClosePrice > RangeHi");
         InRange = false;                    //return;
      }
      if (ClosePrice < RangeLo)                     // i.e. Last completed bar (#1) close price < RangeLo - bars 2 - 22)
      {  if ( MTF == true ) Report_StringError("Both","100163 NBC ClosePrice < RangeLo");
         if  (OpenTrade(sellPrice, ORDER_TYPE_SELL) == false) return;
         if ( MTF == true ) Report_StringError("Both","100164 NBC ClosePrice < RangeLo");
         InRange = false;                    //return;
      }
//...........................................................................................................

I am using FXChoice and have asked them for any help they may be able to give about the account status.

As stated before this is my first venture into writing in MT5 (hundreds of routines in MT4) - so just wondering if I missed something.

 

Forum on trading, automated trading systems and testing trading strategies

What Reasons for a Trade to Close so quickly

Enrique Dangeroux, 2022.10.27 11:42

For exchange there also can be only 1 position.

Maybe also check your logic. If you get a buy signal expecting price to rise, and 2 seconds later you get a sell signal expecting price to fall, frankly your signals are no good.


Well... not maybe. The flaw is in your logic. Check it, fix it. We can not, your broker can not.

 

Thanks everyone for your help.


I believe I have tracked the problem and corrected it.

I had a secondary EA running to monitor all the single charts listing all current trades, balance, equity etc.  This should have been display only but a default 'flag' was set incorrectly and caused the EA to check some positions and found a criteria to close a trade.

[The EA also has some Buttons to enable me to Close All Trades, Close All Charts, Open All charts - all of which actived with code in the OnChartEvent]

My mistake and apologise.  Thanks for all your help which 'forced me' to look elsewhere


Mega thanks again

Reason: