Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

premature closure of swing trade #399

Open
mngz47 opened this issue Mar 12, 2024 · 11 comments
Open

premature closure of swing trade #399

mngz47 opened this issue Mar 12, 2024 · 11 comments

Comments

@mngz47
Copy link

mngz47 commented Mar 12, 2024

I ran the EA on daily timeframe GBPUSD and it was able to spot swing trade for $20 to $200 risk reward. The trade was closed prematurely at $2.

I think its better once the trade is opened and the risk reward is set to let it play out before planning new trade.

Therefore the trade close conditions need to be removed. The risk-reward is sufficient for professional money management and controlled loss.

Where is close conditions file located I can have a look.

@kenorb
Copy link
Member

kenorb commented Mar 12, 2024

There are a few ways how trades can be closed automatically.

  • Close loss/profit input parameters (when set to non-zero value). These values works in stealth mode, checked periodically, so not visible on SL/TP). Set it to zero to disable.
  • Close time input parameter (when set to non-zero value) which closes trades based after selected time or number of candles. Set it to zero to disable.
  • EA's tasks (Advanced and Rider): Orders are closed when action based on condition is met. To disable, disable closing actions or use tasks' filter (Advanced).
  • Opposite signal of the strategy. E.g. when strategy signals Buy, all managed Sell orders from that strategy for the given timeframe are closed and other way round (Sell signal closes Buys). To postpone closure of that kind, you can set Close Filter to non-zero value, which will close trades based on the selected filters. To completely disable opposite signals, this should be disabled as part of the strategy (code only) as of now.
  • Closure on SL/TP which is calculated by the given strategy based on the main indicator values. For example, MA strategy could close orders when price hits MA line, Bands and Envelopes strategies on price hitting its bands. Basically it's an integral part of each strategy logic.

To identify how the trade was closed, you should look at the trade's closure comment.

@mngz47
Copy link
Author

mngz47 commented Mar 12, 2024

image

I have reinitialized the EA with the above settings on demo account. If another trade closes prematurely I will check closure comment on journal tab in mt4 and let you know.

image

I think the on each day close not in trend task was responsible for closing my previous trade.

@mngz47
Copy link
Author

mngz47 commented Mar 12, 2024

Which Strategy is being used on daily timeframe?

@kenorb
Copy link
Member

kenorb commented Mar 12, 2024

Which Strategy is being used on daily timeframe?

There are no strategies set on daily timeframe. Not yet.

@mngz47
Copy link
Author

mngz47 commented Mar 13, 2024

I recommend Support Resistance Used by the banks. The perks is stable order management.

Below is an example with 160 to 267 risk reward. Very stable - pans out multiple days.

image

@kenorb
Copy link
Member

kenorb commented Mar 13, 2024

I recommend Support Resistance Used by the banks

Is there a code for it?

@mngz47
Copy link
Author

mngz47 commented Mar 25, 2024

Convert this pine script to C Lang

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © faytterro

//@Version=5
indicator("Support and Resistance", overlay = true, max_bars_back =1500)
trn=50
o = input.int(0, "previous supports and resistances" , minval = 0)
len=input.int(20, "previous supports and resistances length", minval = 1)
cs = input.color(color.rgb(0,255,0,trn), "Support Color")
cr = input.color(color.rgb(255,0,0,trn), "Resistance Color")

r = high<low[2]-(high[2]-low[2])
and math.abs(close[1]-open[1])>(high[2]-low[2])*2
r2 = high<math.min(low[3],low[4])-(math.max(high[3],high[4])-math.min(low[3],low[4]))
and math.abs(close[1]-open[2])>(math.max(high[3],high[4])-math.min(low[3],low[4]))*2
for i=1 to 4
r2:= r2 and r2[i]==false
r:= r and r2[i-1]==false
s= low>high[2]-(high[2]-low[2])
and math.abs(close[1]-open[1])>(high[2]-low[2])*2
s2 = low>math.max(high[3],high[4])+(math.max(high[3],high[4])-math.min(low[3],low[4]))
and math.abs(close[1]-open[2])>(math.max(high[3],high[4])-math.min(low[3],low[4]))*2
for i=1 to 4
s2 := s2 and s2[i]==false
s:= s and s2[i-1]==false

ass= ta.crossover(close,ta.valuewhen(r,high[2],o))
for i = 1 to ta.barssince(r)
ass:= ass and ass[i]==false
k=ta.barssince(ass)<ta.barssince(r)? ta.barssince(ass) : -2
box=box.new(ta.valuewhen(r,bar_index,o)-2,
ta.valuewhen(r,high[2],o),
o==0? last_bar_index-k :ta.valuewhen(r,bar_index,o)-2+len,
ta.valuewhen(r,low[2],o), bgcolor = cr, border_color = color.rgb(71, 89, 139,100))
box.delete(box[1])

bass= ta.crossunder(close,ta.valuewhen(r,high[2],o))
for i = 1 to ta.barssince(r)
bass:= bass and bass[i]==false
bk=ta.barssince(bass)<ta.barssince(r)? ta.barssince(bass) : -2
bbox=box.new(last_bar_index-k,
ta.valuewhen(r,high[2],o),
last_bar_index-bk,ta.valuewhen(r,low[2],o), bgcolor = cs, border_color = color.rgb(71, 89, 139,100))
box.delete(bbox[o<1? 1 : 0])

ass2= ta.crossover(close,math.max(ta.valuewhen(r2,high[3],o), ta.valuewhen(r2,high[4],o)))
for i = 1 to ta.barssince(r2)
ass2:= ass2 and ass2[i]==false
k2=ta.barssince(ass2)<ta.barssince(r2)? ta.barssince(ass2) : -2
box2=box.new(ta.valuewhen(r2,bar_index,o)-4, ///last_bar_index-ta.barssince(r2)-4
math.max(ta.valuewhen(r2,high[3],o), ta.valuewhen(r2,high[4],o)),
o==0? last_bar_index-k2 : ta.valuewhen(r2,bar_index,o)-4 + len ,
math.min(ta.valuewhen(r2,low[3],o), ta.valuewhen(r2,low[4],o)),
bgcolor = cr, border_color = color.rgb(71, 89, 139,100))
box.delete(box2[1])

bass2= ta.crossunder(close,math.max(ta.valuewhen(r2,high[3],o), ta.valuewhen(r2,high[4],o)))
for i = 1 to ta.barssince(r2)
bass2:= bass2 and bass2[i]==false
bk2=ta.barssince(bass2)<ta.barssince(r2)? ta.barssince(bass2) : -2
bbox2=box.new(last_bar_index-k2,
math.max(ta.valuewhen(r2,high[3],o), ta.valuewhen(r2,high[4],o)),
last_bar_index-bk2,
math.min(ta.valuewhen(r2,low[3],o), ta.valuewhen(r2,low[4],o)),
bgcolor = cs, border_color = color.rgb(71, 89, 139,100))
box.delete(bbox2[o==0? 1:0])

akk = ta.crossunder(close,ta.valuewhen(s,low[2],o))
for i=1 to ta.barssince(s)
akk:= akk and akk[i]==false
k4=ta.barssince(akk)<ta.barssince(s)? ta.barssince(akk) : -2
box4=box.new(ta.valuewhen(s,bar_index,o)-2,
ta.valuewhen(s,high[2],o),
o==0? last_bar_index-k4 :ta.valuewhen(s,bar_index,o)-2+len,
ta.valuewhen(s,low[2],o),
bgcolor = cs, border_color = color.rgb(71, 89, 139,100))
box.delete(box4[1])

akk2 = ta.crossunder(close,math.min(ta.valuewhen(s2,low[3],o),ta.valuewhen(s2,low[4],o)))
for i=1 to ta.barssince(s2)
akk2:= akk2 and akk2[i]==false
k5=ta.barssince(akk2)<ta.barssince(s2)? ta.barssince(akk2) : -2
box5=box.new(ta.valuewhen(s2,bar_index,o)-4,
math.max(ta.valuewhen(s2,high[3],o),ta.valuewhen(s2,high[4],o)),
o==0? last_bar_index-k5 : ta.valuewhen(s2,bar_index,o)-4+len ,
math.min(ta.valuewhen(s2,low[3],o),ta.valuewhen(s2,low[4],o)),
bgcolor = cs, border_color = color.rgb(71, 89, 139,100))
box.delete(box5[1])

bakk = ta.crossover(close,ta.valuewhen(s,low[2],o))
for i=1 to ta.barssince(s)
bakk:= bakk and bakk[i]==false
bk4=ta.barssince(bakk)<ta.barssince(s)? ta.barssince(bakk) : -2
bbox4=box.new(last_bar_index-k4,
ta.valuewhen(s,high[2],o),
last_bar_index-bk4,
ta.valuewhen(s,low[2],o),
bgcolor = cr, border_color = color.rgb(71, 89, 139,100))
box.delete(bbox4[o==0? 1:0])

bakk2 = ta.crossover(close,math.min(ta.valuewhen(s2,low[3],o),ta.valuewhen(s2,low[4],o)))
for i=1 to ta.barssince(s2)
bakk2:= bakk2 and bakk2[i]==false
bk5=ta.barssince(bakk2)<ta.barssince(s2)? ta.barssince(bakk2) : -2
bbox5=box.new(last_bar_index-k5,
math.max(ta.valuewhen(s2,high[3],o),ta.valuewhen(s2,high[4],o)),
last_bar_index-bk5,
math.min(ta.valuewhen(s2,low[3],o),ta.valuewhen(s2,low[4],o)),
bgcolor = cr, border_color = color.rgb(71, 89, 139,100))
box.delete(bbox5[o==0?1:0])

@mngz47
Copy link
Author

mngz47 commented Mar 25, 2024

@mngz47
Copy link
Author

mngz47 commented Apr 1, 2024

image

after using recommended settings this is the result. but I'm not sure of risk reward because there is no stop loss

@kenorb
Copy link
Member

kenorb commented Apr 2, 2024

After using recommended settings this is the result. but I'm not sure of risk reward because there is no stop loss

SL is set after some period of time, depending on the strategy. You can set max risk reward based on the Close loss/profit stops inputs which is going to be tracked by EA (not visible).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants