Code help required please | Forex Factory

HeroPoker_HeroPoker扑克_HeroPoker德扑圈官网

Attachments: Code help required please

Code help required please

Can anyone please correct this formula to enter a sell after the green candle? I just cant get anywhere near for some reason?
Attached Image (click to enlarge)
Click to Enlarge

Name: f1.PNG
Size: 3 KB

this is what is happening below
Attached Image

This is where I want it to enter a sell at the bottom of the green candle
Attached Image (click to enlarge)
Click to Enlarge

Name: 1.PNG
Size: 2 KB


I just cant get near it this morning I must of had too much beer last night
Geoff
I guess you're looking at the current candle but numbered it as "1" instead of "0".

Should be something like this:

Inserted Code
High[1] > High[0] &&
Ask <= Low[1]
MT4/MT5 EAs/Indicators/Alerts coder
Thanks but I've just ran it and it didn't trade at all in that area, this is why Im puzzled

thanks see pics
Geoff
Attached Image (click to enlarge)
Click to Enlarge

Name: 4.PNG
Size: 4 KB

Attached Image (click to enlarge)
Click to Enlarge

Name: 3.PNG
Size: 6 KB
Attached Image (click to enlarge)
Click to Enlarge

Name: 5.PNG
Size: 3 KB

simplified without distant pips, still as last picture, I cant figure it out ??
I always thought the last candle closed was 1 and the one before was 2
{image} simplified without distant pips, still as last picture, I cant figure it out ?? I always thought the last candle closed was 1 and the one before was 2
Yes last closed is 1. I was talking about the current candle 0.

Where you're looking for a trade, the High[2] isn't higher than High[1].

And your "sell @GR candle" isn't correct as your code is Ask <= Low[2] ... which is comparing the current Ask price (within the big red candle) with the low of 2 candles before (the red one).
MT4/MT5 EAs/Indicators/Alerts coder
{quote} Yes last closed is 1. I was talking about the current candle 0. Where you're looking for a trade, the High[2] isn't higher than High[1]. And your "sell @GR candle" isn't correct as your code is Ask <= Low[2] ... which is comparing the current Ask price (within the big red candle) with the low of 2 candles before (the red one).
the image is on there above marked on image it抯 a rejection of a buy candle I want to use the signal to sell
look at the top image where it says sell
geoff
[quote=FerruFx;15549526]{quote} Yes last closed is 1. I was talking about the current candle 0. Where you're looking for a trade, the High[2] isn't higher than High[1]. And your "sell @GR candle" isn't correct as your code is Ask <= Low[2] ... which is comparing the current Ask price (within the big red candle) with the low of 2 candles before (the red one).[/quote

you抳e lost me just write a formula I can try please that will sell below the green candle

cheers
you抳e lost me just write a formula I can try please that will sell below the green candle
You've lost me ... Just write your rules clearly highlightning all the candles involved.

BTW, if you're backtesting, your ASK price is probably way too far due to high spread at market close.
MT4/MT5 EAs/Indicators/Alerts coder
Attached Image (click to enlarge)
Click to Enlarge

Name: 22.PNG
Size: 2 KB

It's simple all I want is the code to place a sell after the green hammer candle in the picture above, It's ok if you can't manage it my friend it's caught me out, I just thought I would just change a couple of numbers etc and it would be fine but I've had it every way possible and still cant get it to drop a sell in just after the green candle. Thanks for trying.

Geoff

the 2 ma lines are 5 and 8 ema in a sell position
  • Joined Feb 2025 | Status: Developer by Choice Trader by Heart | 174 Posts
{image} It's simple all I want is the code to place a sell after the green hammer candle in the picture above, It's ok if you can't manage it my friend it's caught me out, I just thought I would just change a couple of numbers etc and it would be fine but I've had it every way possible and still cant get it to drop a sell in just after the green candle. Thanks for trying. Geoff the 2 ma lines are 5 and 8 ema in a sell position
Maybe this can help:

Inserted Code
if (
   MAfast < MAslow &&
   High[2] > High[1] &&
   Bid >= High[2] && // Sell at or above the high of the green candle
   GETORDERS(my_Orderdata) == 0 &&
   my_Orderdata.AllowSell )
{
   // Place sell order here
}

If you can give a bit of information around your strategy and the surrounding code, I might have a better idea on how to guide you. I am mainly proficient in MQL5 so apologies if doesn't work out, as I believe the syntax is of MQL4.
?Developed by MMQ
  • Joined Feb 2025 | Status: Developer by Choice Trader by Heart | 174 Posts
Alternative consideration:

Inserted Code
if (
    MAfast < MAslow &&
    High[2] > High[1] &&           // Candle [2] was green
    High[1] >= High[2] &&          // Price broke above it (candle [1])
    Bid <= Open[1] &&              // Now retracing back down
    GETORDERS(my_Orderdata) == 0 &&
    my_Orderdata.AllowSell )
{
     // Sell on pullback after breakout
}

If you want to sell after price breaks above and then comes back down, the above code executes that.

Note: Indentation is a bit off, it will likely need fixing in the IDE
?Developed by MMQ
Hi, You are quoting bid? you must be looking at the wrong green candle, I am wanting to sell below the green candle marked with a white line.

Geoff
Attached Image (click to enlarge)
Click to Enlarge

Name: new1.PNG
Size: 3 KB
  • Joined Feb 2025 | Status: Developer by Choice Trader by Heart | 174 Posts
Hi, You are quoting bid? you must be looking at the wrong green candle, I am wanting to sell below the green candle marked with a white line. Geoff
Yes, bid is used for sell. Try changing your code with this:

Inserted Code
Bid >= Low[2] &&

And share the results, I might get a better understanding
?Developed by MMQ
  • Joined Feb 2025 | Status: Developer by Choice Trader by Heart | 174 Posts
Also, during the strategy tester, turn on visual mode and see the bid/ask prices. Your logic might be correct and the real issue could be spread or slippage

Note on bid/ask: Using Ask for sell orders will cause entries at incorrect price levels due to the spread offset.
?Developed by MMQ
Also, during the strategy tester, turn on visual mode and see the bid/ask prices. Your logic might be correct and the real issue could be spread or slippage Note on bid/ask: Using Ask for sell orders will cause entries at incorrect price levels due to the spread offset.
ok sounds possible but slippage is 3 spread is 6 can you please write the code you think is correct I will copy it in and run tests when I get home she抯 got me in Asda now

cheers much appreciated
Also, during the strategy tester, turn on visual mode and see the bid/ask prices. Your logic might be correct and the real issue could be spread or slippage Note on bid/ask: Using Ask for sell orders will cause entries at incorrect price levels due to the spread offset.
Hi, This is the best I can get and your figures made no difference but I appreciate you trying to help, the pictures are from strategy tester visual, its not great where it is trading from and it may be the spread, who knows, try it yourself I will attach it try if you like or bin it, I am interested in perfection only when I can get it. I've only been coding for about 11 years but I've been in software all my life, daft things like this bug me.

Regards
Geoff Hornibrook

Attached File(s)
File Type: ex4 test.ex4   60 KB | 27 downloads

Attached Image (click to enlarge)
Click to Enlarge

Name: best1.PNG
Size: 3 KB

Attached Image
It should be High[1] > High[2]
if You want the hammer to be higher than the bar before it.
MetaTrader 4 - so many advantages.
  • Joined Feb 2025 | Status: Developer by Choice Trader by Heart | 174 Posts
{quote} Hi, This is the best I can get and your figures made no difference but I appreciate you trying to help, the pictures are from strategy tester visual, its not great where it is trading from and it may be the spread, who knows, try it yourself I will attach it try if you like or bin it, I am interested in perfection only when I can get it. I've only been coding for about 11 years but I've been in software all my life, daft things like this bug me. Regards Geoff Hornibrook {file} {image} {image}
I hear you, this happens all the time. You've coded such a an elaborate project and it's the little things that you somehow can't figure out. DRIVES ME NUTS lol

Anyways, I don't have MT4 so unfortunately I can't test it, but I do see that you have now added the DistancePips complexity back, which does change things.

However, I can't figure out why this doesn't work anyways. It should in theory. You can try debugging this specific time-period and seeing why it's entering where it's not suppose to. What condition is being met here. Logging is terrible in MQL4/5 but it's the only option left. For instance, you might see that there's an error at this specific moment like (Market Closed) which is common on MT5 and that's why you get a "delayed" entry. Or some other "feature" of this wonderland

Or hopefully other people can figure out what's wrong and give you an appropriate solution. Best of luck
?Developed by MMQ
Can anyone please correct this formula to enter a sell after the green candle? I just cant get anywhere near for some reason?{image} this is what is happening below {image} This is where I want it to enter a sell at the bottom of the green candle {image} I just cant get near it this morning I must of had too much beer last night Geoff
All the previous code examples don't check for a green bar. A green (bullish) bar is defined by the close price being higher than the open price, independant of the wicks. So, instead of checking Highs/Lows you have to check Open/Close of the bar in question.

Attached Image (click to enlarge)
Click to Enlarge

Name: sell-condition.png
Size: 6 KB
It takes blood, sweat and enough tears to wash away the blood.