molanis.com/forum - Tools for MetaTrader : The place to ask about the best expert advisor builder, expert advisor downloads, and expert advisor programming

AFTER YOU REGISTER SEND US AN EMAIL TO ACTIVATE YOUR ACCOUNT - Before posting:-1- Please read the user guide -2- Try the examples -3- Search in the forum
It is currently Sun May 12, 2024 10:19 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: AutoAdjustSLTP
PostPosted: Wed Nov 21, 2012 10:55 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
mods, AutoAdjustSLTP looks like it is intended to be an input (extern bool) however it's hidden as just a bool. It's set to false, and additionally, it's set to false inside the start function. A few questions:

1. The code seems self explanatory, so why is it hidden/deactivated?

2. Will AutoAdjustSLTP operate properly if I activate it?

3. Even if it won't operate properly, is the code functional enough for me to edit in my own condition(s) and adjustment math? This is my end goal.

Thanks.

Edit: I answered my own question with the manual... once again. :oops:

This topic parallels the MaxMartingaleSize topic I posted a short while ago: http://www.molanis.com/forum/viewtopic.php?p=9888#p9888.

AutoAdjustSLTP is in the manual as an input as well, and the manual states exactly what the code does. No need to reply. I'm only leaving this post up to help other lost souls who have SB Pro.

Note: If you have SB standard, you have no idea what I'm talking about because you can't correct an input that you can't see. Same with MaxMartingaleSize. So, upgrade to Pro I guess.

_________________
I'm not a programmer, but I play one on TV.


Top
 Profile  
 
 Post subject: Re: AutoAdjustSLTP
PostPosted: Sun Nov 25, 2012 6:30 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
Well, I'm glad no one replied to my first post because I was on the wrong track. I was looking for:

(a) a way to set a stoploss at the previous candle's Low for a buy trade, and the previous candle's High for a sell trade; and

(b) a way to set a stoploss at BEpipBuffer +/- entry price only if price hits BETpipBuffer +/- entry price.

From my understanding of Molanis code, AutoAdjustSLTP is only suitable for use if there is a preexisting stoploss in place. So I looked under ExecuteOrderinTwo, and came up with the following code modifications. I posted another thread on how to get the lastOrderPrice. Obviously, all variables are declared up top and defined under start. Molanis' PipMultiplier and Point are used to multiply my extern int's into useable numbers as BEpipBuffer and BETpipBuffer. It compiled without errors, and I'm about to test it.

Just look for the hatchet marks /////////// and you will know where I chopped up the code. Hopefully this helps someone, somewhere.

Code:
        if (golong_bn) {
              price_bn = NormalizeDouble(MarketInfo(symbol_bn,MODE_ASK),digits_bn);
              // UsePrevHighLowSL for buy trades--Created by User ///////////////////////////////////////////////
              if (( UsePrevHighLowSL ) // if UsePrevHighLowSL is true
                 && ( stoploss_bn == 0 )) { // and initial stop loss is set to zero
                 stoploss_bn = NormalizeDouble(prevLow, digits_bn); // set sl at previous price bar Low
               Print("M-Stop loss set at previous Low. ","SL= ",stoploss_bn,"."); }
            ///////////////////////////////////////////////////////////////////////////////////////////////////
            // UseBreakEvenSL for buy trades--Created by User /////////////////////////////////////////////////
            if (( UseBreakEvenSL ) // if UseBreakEvenSL is true
               && ( stoploss_bn == 0 ) // and intial stoploss is set to zero
               && ( currPrice >= BETpipBuffer + currPrice )) { // and price hits BreakEvenTrigger
               stoploss_bn = NormalizeDouble(BEpipBuffer + lastOrderPrice, digits_bn); // set sl at BreakEvenSL
               Print("M-Stop loss set at BreakEven. ","SL= ",stoploss_bn,"."); }
            ///////////////////////////////////////////////////////////////////////////////////////////////////
             if (stoploss_bn > 0) {
                  stoploss_bn = NormalizeDouble(price_bn-stoploss_bn*points_bn, digits_bn);
                  stoploss_bn = CheckStopLoss(symbol_bn, price_bn, stoploss_bn);
            }
            if (takeprofit_bn>0) {
               takeprofit_bn= NormalizeDouble(price_bn+takeprofit_bn*points_bn, digits_bn);
               takeprofit_bn = CheckTakeProfit(symbol_bn, price_bn, takeprofit_bn);
            }
        } else {  // go short set up
            price_bn = NormalizeDouble(MarketInfo(symbol_bn,MODE_BID),digits_bn);
            // UsePrevHighLowSL for sell trades--Created by User //////////////////////////////////////////////
            if (( UsePrevHighLowSL ) // if UsePrevHighLowSL is true
               && ( stoploss_bn == 0 )) { // and initial stop loss is set to zero
               stoploss_bn = NormalizeDouble(prevHigh, digits_bn); // adjust sl to previous price bar High
               Print("M-Stop loss set at previous High. ","SL= ",stoploss_bn,"."); }
            // UseBreakEvenSL for sell trades--Created by User /////////////////////////////////////////////////
            if (( UseBreakEvenSL ) // if UseBreakEvenSL is true
               && ( stoploss_bn == 0 ) // and intial stoploss is set to zero
               && ( currPrice <= BETpipBuffer - currPrice )) { // and price hits BreakEvenTrigger
               stoploss_bn = NormalizeDouble(BEpipBuffer - lastOrderPrice, digits_bn); // set sl at BreakEvenSL
               Print("M-Stop loss set at BreakEven. ","SL= ",stoploss_bn,"."); }
            ///////////////////////////////////////////////////////////////////////////////////////////////////
            if (stoploss_bn > 0) {
              stoploss_bn = NormalizeDouble(price_bn+stoploss_bn*points_bn, digits_bn);
              stoploss_bn = CheckStopLoss(symbol_bn, price_bn, stoploss_bn);
            }
            if (takeprofit_bn>0) {
              takeprofit_bn= NormalizeDouble(price_bn-takeprofit_bn*points_bn, digits_bn);
              takeprofit_bn = CheckTakeProfit(symbol_bn, price_bn, takeprofit_bn);
            }

_________________
I'm not a programmer, but I play one on TV.


Top
 Profile  
 
 Post subject: Re: AutoAdjustSLTP
PostPosted: Sun Nov 25, 2012 10:03 pm 
Offline

Joined: Tue Dec 22, 2009 12:22 am
Posts: 1761
It would be nice if you post a complete ea to see it. I am really interested to see your modifications.
AutoAdjustSLTP was created to keep a constant ratio between tp and sl but nobody really uses it.


Top
 Profile  
 
 Post subject: Re: AutoAdjustSLTP
PostPosted: Mon Nov 26, 2012 10:01 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
molanisfx wrote:
It would be nice if you post a complete ea to see it. I am really interested to see your modifications.
AutoAdjustSLTP was created to keep a constant ratio between tp and sl but nobody really uses it.


Didn't know I was allowed to do that here. Here you go.

Notes:
- I've made other changes to the Molanis code.
- Ctrl-F, Created by User, to go to all changes.
- I have not seen the conditons for a trade arise, so the EA has not been tested.
- I'll take any feedback offered.


Attachments:
The8_EA_v1g.mq4 [95.95 KiB]
Downloaded 454 times

_________________
I'm not a programmer, but I play one on TV.
Top
 Profile  
 
 Post subject: Re: AutoAdjustSLTP
PostPosted: Tue Nov 27, 2012 9:44 pm 
Offline

Joined: Tue Dec 22, 2009 12:22 am
Posts: 1761
Nice work.
For Get last open trade price I would put OrdersTotal() in a variable to avoid recalculating it every time
Also, I would add support for manual trades that have a magic number = 0 (you can see some logic like that in some of our code). You may create the whole thing as a function and add the pair as an input. Right now you are limited to the pair in the chart.
For the sl and break even you may want to add a check that makes sure the stops are valid since you use the low of the previous day which could be above the current price. Did you manage to backtest this with mt4? This is like a multi timeframe ea since the stops use a daily chart and maybe you trade every 4 hours so your backtesting may not be accurate.


Top
 Profile  
 
 Post subject: Re: AutoAdjustSLTP
PostPosted: Tue Nov 27, 2012 11:35 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
molanisfx wrote:
Nice work.

Well... not so nice. :( I have two sell entries, each with no stops even though UsePrevHighLowSL was set to true. Both stops should have been valid, as each previous High was well above each respective entry. Screenshots attached. Any suggestions?
Attachment:
au.gif
au.gif [ 25.35 KiB | Viewed 7659 times ]

Attachment:
gu.gif
gu.gif [ 25.1 KiB | Viewed 7681 times ]


molanisfx wrote:
For Get last open trade price I would put OrdersTotal() in a variable to avoid recalculating it every time.

Got it. Will do. Thank you.

molanisfx wrote:
Also, I would add support for manual trades that have a magic number = 0 (you can see some logic like that in some of our code). You may create the whole thing as a function and add the pair as an input. Right now you are limited to the pair in the chart.

I built multipair EA's in the past straight from SB, but they weren't as resource efficient as running separate SB EA's on individual charts in MT4. I don't know why.

molanisfx wrote:
For the sl and break even you may want to add a check that makes sure the stops are valid since you use the low of the previous day which could be above the current price.

Can't believe I missed this. Will do. Thanks again.

molanisfx wrote:
Did you manage to backtest this with mt4? This is like a multi timeframe ea since the stops use a daily chart and maybe you trade every 4 hours so your backtesting may not be accurate.

I gave up on backtesting some time ago due to tick data collection issues. The EA is intended for trading the D1 timeframe only.

_________________
I'm not a programmer, but I play one on TV.


Top
 Profile  
 
 Post subject: Re: AutoAdjustSLTP
PostPosted: Wed Nov 28, 2012 12:03 am 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
:oops: Regarding my missing stops...

Code:
if ( my_ticket > 0 && (stoploss_bn != 0 || takeprofit_bn != 0) )


Inside that Molanis condition, my condition joined by && with UsePrevHighLowSL is:

Code:
if ( stoploss_bn == 0 )

_________________
I'm not a programmer, but I play one on TV.


Top
 Profile  
 
 Post subject: Re: AutoAdjustSLTP
PostPosted: Wed Nov 28, 2012 1:12 pm 
Offline

Joined: Tue Dec 22, 2009 12:22 am
Posts: 1761
Not sure. Maybe you need to print some values to check it is working fine.


Top
 Profile  
 
 Post subject: Re: AutoAdjustSLTP
PostPosted: Thu Nov 29, 2012 4:19 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
molanisfx wrote:
Not sure. Maybe you need to print some values to check it is working fine.


Sorry... my last post was not a question, rather an admission of sorts.

A condtion of stoploss_bn == 0 nested within a condition of stoploss != 0 is obviously never going to read true.

Anyway... I fixed/updated some other things in the EA. Anyone who would like to follow its progress can do so at:
http://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=30623#p30623

_________________
I'm not a programmer, but I play one on TV.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by Molanis © 2009