MQL4 programming, dodging breakouts

 

Im working on my first EA.

Ive got hostorical data dating back a couple years to backtest and one case i need help with is when the bottom completely drops out. as seen in the picture im ataching. Clipped from my EUR-USD M15 backtesting chart, the trade before the dropout is satisfactory however it buys and hits the stoploss multiple times therafter.

I need some help on programming to avoid cases like this.

So far the EA works fairly well except for repeated stoploss hits like this. completely cooks the profit margin over a 2 year test run.


EUR-USD M15 Flagpole

 

I see you have fractals showing on the chart. Do you use them in your routine? You had two high fractals (the second one lower than the first) just before the Spot Price dropped below the centerline of your bollinger band series. That seems like a petty good signal that things are heading south.



 

Not using fractals. Forgot to remove them before i took the screenshot.

Im quite green when it comes to forex trading and most indicators and what they each represent are still quite alien to me so ive been making due with the few that ive got the gist of.

I got started with forex on demo accounts, still havnt tried live, trading 'naked', no indicators, and only since trying to program an EA have I seriously taken a look at them and started learning the lingo.

Ill have to review chart data and see if i can recognize the pattern you suggest, then figure out how to program it.

Meanwhile, are there any other indicators anyone can suggest ? I still dont understand the significance of most of them.

 

C

Various possibilities

Seems you are opening mid-bar, so consider:-

1) Using a static integer to track when you have opened on the current bar, reset the counter to zero on first tick of next bar

2) Track the body size of the current candle compared to the current ATR, i.e. if body 2xATR then DONT ORDER NO MORE!

FWIW

-BB-

 
BarrowBoy wrote >>

C

Various possibilities

Seems you are opening mid-bar, so consider:-

1) Using a static integer to track when you have opened on the current bar, reset the counter to zero on first tick of next bar

2) Track the body size of the current candle compared to the current ATR, i.e. if body 2xATR then DONT ORDER NO MORE!

FWIW

-BB-

Anyone know exactly how many ticks to a bar or do i have to go by time, or is there a trick to track the bars start and end in the editor ?

I wanna configure so it can work in all timeframes. once thats done ill tune some special timeframe rules if any problems crop up.

 
Cranium:

Anyone know exactly how many ticks to a bar or do i have to go by time, or is there a trick to track the bars start and end in the editor ?

I wanna configure so it can work in all timeframes. once thats done ill tune some special timeframe rules if any problems crop up.

The number of ticks to a bar varies. In fx trading, the volume is the number of ticks for a given bar.


https://docs.mql4.com/predefined/variables/Volume

 
Cranium wrote >>

Anyone know exactly how many ticks to a bar or do i have to go by time, or is there a trick to track the bars start and end in the editor ?

I wanna configure so it can work in all timeframes. once thats done ill tune some special timeframe rules if any problems crop up.

You can track a bars open and close time but acting on the timing depends on a tick arriving anyway, so I generally work off ticks rather than time (except for OrderExpiry)

To limit trades to n per bar, use something like this, OTTOMH

extern int Max.Trades.Per.Bar = 2;



static int Trades.So.Far.In.Bar;
init()
  {
    Trades.So.Far.In.Bar = 0; // Handle loading of EA mid bar
  }


start()

{

   if (Volume[0]==1) Trades.So.Far.In.Bar = 0; // Reset counter on first tick only



   if (Trades.So.Far.In.Bar < Max.Trades.Per.Bar ) // Check not already up to limit for bar
    {

      // Do trade logic

      // Do OrderSend stuff and increment counter
     
      Trades.So.Far.In.Bar = Trades.So.Far.In.Bar+1 

    }

    



  return (0);

}

A static variable preserves its value between ticks

Good Luck

-BB-

 
BarrowBoy:

You can track a bars open and close time but acting on the timing depends on a tick arriving anyway, so I generally work off ticks rather than time (except for OrderExpiry)

To limit trades to n per bar, use something like this, OTTOMH

A static variable preserves its value between ticks

Good Luck

-BB-

Thank you very much.

After integrating your thoughts to work with my program it stopped multiple buys per bar.

The EA is getting better, still isn't a winner yet, but it takes longer to lose all the money :P

Reason: