• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 2:43am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 2:43am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

How do you adjust font size in meta trader? 18 replies

how to adjust the vertical horizon of mt4 6 replies

How does the price adjust after the News?! 2 replies

Can I adjust period separators??? 1 reply

Trying to "adjust" some code 1 reply

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe

S/L won't adjust

  • Post #1
  • Quote
  • First Post: Feb 14, 2008 2:42am Feb 14, 2008 2:42am
  •  Pip Parade
  • | Joined Dec 2007 | Status: ... often wrong but never in doubt | 222 Posts
I've got an EA in place which carries a "Move Stop Loss" function. The idea is to get to break-even asap then secure a small profit before allowing the trade to run. Unfortunately, it (they) don't seem to trigger consistently.

Would appreciate analysis/suggestions by the programmers in the group. Parts of the code is below:



//---- input parameters
extern int TargetMoveStopPipsA=15;
extern int StopMovePipsA=0;
extern int TargetMoveStopPipsB=30;
extern int StopMovePipsB=5;

------------------------------------------

if (OrderFind(magicno))
{//open order
if (glbOrderType==OP_BUY)
{//long open
if (Bid-glbOpenPrice>TargetMoveStopPipsA*Point && glbStopPrice<glbOpenPrice)OrderModify(glbOrderTicket,
OrderOpenPrice(), NormalizeDouble(glbOpenPrice+StopMovePipsA*Point,Digits), OrderTakeProfit( ) , 0, Orange) ;
}

-----------------------------------------

if (OrderFind(magicno))
{//open order
if (glbOrderType==OP_BUY)
{//long open
if (Bid-glbOpenPrice>TargetMoveStopPipsB*Point && glbStopPrice<glbOpenPrice)OrderModify(glbOrderTicket,
OrderOpenPrice(), NormalizeDouble(glbOpenPrice+StopMovePipsB*Point,Digits), OrderTakeProfit( ) , 0, Orange) ;
}


Thanks ...
  • Post #2
  • Quote
  • Feb 14, 2008 3:34pm Feb 14, 2008 3:34pm
  •  magnumfreak
  • Joined Nov 2007 | Status: Trying manual mode again | 2,210 Posts
Can you post your OrderFind function? I need to make sure your are using the orderselect function.
 
 
  • Post #3
  • Quote
  • Feb 14, 2008 3:49pm Feb 14, 2008 3:49pm
  •  Pip Parade
  • | Joined Dec 2007 | Status: ... often wrong but never in doubt | 222 Posts
Will do ...

Say, - I notice this section is within the NewBar command (part of which was not included in this post) ... should it be moved out??? If so, to which section???

----------------------------------------------------------------------

if (NewBar())


if (OrderFind(magicno))
{//open order
if (glbOrderType==OP_BUY)
{//long open
if (Bid-glbOpenPrice>TargetMoveStopPipsA*Point && glbStopPrice<glbOpenPrice)OrderModify(glbOrderTicket,
OrderOpenPrice(), NormalizeDouble(glbOpenPrice+StopMovePipsA*Point,Digits), OrderTakeProfit( ) , 0, Orange) ;
}
else
{//short open
if (glbOpenPrice-Ask>TargetMoveStopPipsA*Point && glbStopPrice>glbOpenPrice)OrderModify(glbOrderTicket,
OrderOpenPrice(), NormalizeDouble(glbOpenPrice-StopMovePipsA*Point,Digits), OrderTakeProfit( ) , 0, Orange) ;
}
}

if (OrderFind(magicno))
{//open order
if (glbOrderType==OP_BUY)
{//long open
if (Bid-glbOpenPrice>TargetMoveStopPipsB*Point && glbStopPrice<glbOpenPrice)OrderModify(glbOrderTicket,
OrderOpenPrice(), NormalizeDouble(glbOpenPrice+StopMovePipsB*Point,Digits), OrderTakeProfit( ) , 0, Orange) ;
}
else
{//short open
if (glbOpenPrice-Ask>TargetMoveStopPipsB*Point && glbStopPrice>glbOpenPrice)OrderModify(glbOrderTicket,
OrderOpenPrice(), NormalizeDouble(glbOpenPrice-StopMovePipsB*Point,Digits), OrderTakeProfit( ) , 0, Orange) ;
}
}

}// end new bar


------------------------------------------------------------------------
// Also, the input parameters are below


//---- input parameters
extern int ADXthreshold=25;
extern int DIthreshold=5;
extern int magicno=900;
extern double Lots=0.01;
extern int StopLoss=35;
extern int TakeProfit=100;
extern int ClosingConditions=1;
extern int TargetMoveStopPipsA=15;
extern int StopMovePipsA=1;
extern int TargetMoveStopPipsB=30;
extern int StopMovePipsB=5;

-------------------------------------------------------------------------

Thanks ...
 
 
  • Post #4
  • Quote
  • Feb 14, 2008 5:44pm Feb 14, 2008 5:44pm
  •  The Jedi
  • | Joined Mar 2007 | Status: A jedi seeks no title | 657 Posts
Not to piggyback too much, but I have a question which I think may help both of us. Are you trying to get yours to modify more than one order when moving stoplosses? I can't get mine to reliably modify multiple orders and it always breaks down in the order selection process for me. Magnum, I'm definitely looking forward to seeing what you've got on the subject.

I'm going to go ahead and post the code I have for mine so far to see if there isn't anything overlapping between our problems.

Inserted Code
    int total=OrdersTotal();
    for (int cnt=0;cnt<total;cnt++)
    { 
     OrderSelect(cnt, SELECT_BY_POS);   
     int mode=OrderType();    
        if ( OrderSymbol()==Symbol() ) 
        {

        if ( OrderMagicNumber() != MagicNum ) continue;
            if ( mode==OP_BUY )
            {
               int TB1 = GlobalVariableGet("TicketNumberB1GBPJPY");
               int TB2 = GlobalVariableGet("TicketNumberB2GBPJPY");
               if ( Bid-OrderOpenPrice()>Point*(TakeProfit1-1) ) 
               {
               double BuyStop = OrderOpenPrice();
               OrderModify(TB1,OrderOpenPrice(),NormalizeDouble(BuyStop,MarketInfo(Symbol(),MODE_DIGITS)),OrderTakeProfit(),0,LightGreen);
               if ( OrderOpenPrice()-Ask>Point*(TakeProfit1-1) )
               { 
               OrderModify(TB2,OrderOpenPrice(),NormalizeDouble(BuyStop,MarketInfo(Symbol(),MODE_DIGITS)),OrderTakeProfit(),0,Yellow);        
               }
               return(0);
                  }
               }
            if ( mode==OP_SELL )
            {
               int TS1 = GlobalVariableGet("TicketNumberS1GBPJPY");
               int TS2 = GlobalVariableGet("TicketNumberS2GBPJPY");
               if ( OrderOpenPrice()-Bid>Point*(TakeProfit1-1) ) 
               {
               double SellStop = OrderOpenPrice();
               OrderModify(TS1,OrderOpenPrice(),NormalizeDouble(SellStop,MarketInfo(Symbol(),MODE_DIGITS)),OrderTakeProfit(),0,Yellow);        
               if ( OrderOpenPrice()-Bid>Point*(TakeProfit1-1) )
               { 
               OrderModify(TS2,OrderOpenPrice(),NormalizeDouble(SellStop,MarketInfo(Symbol(),MODE_DIGITS)),OrderTakeProfit(),0,Yellow);        
               }
               return(0);
                  }   
            }
       }   
     }
Never underestimate the powers of the Force.
 
 
  • Post #5
  • Quote
  • Feb 14, 2008 6:38pm Feb 14, 2008 6:38pm
  •  Pip Parade
  • | Joined Dec 2007 | Status: ... often wrong but never in doubt | 222 Posts
Jedi,

I don't mind the piggyback at all ... hope it works for everyone involved.

Regarding mine, so far I've only been running 1 trade per pair. I DO run the EA on multiple pairs which keeps the door open for changes around the world but so far have staying with 1 trade per pair and letting it run out.

The narrow focus here is for the S/L to adjust to breakeven, then adjust again, asap.
 
 
  • Post #6
  • Quote
  • Feb 14, 2008 9:52pm Feb 14, 2008 9:52pm
  •  magnumfreak
  • Joined Nov 2007 | Status: Trying manual mode again | 2,210 Posts
Quoting The Jedi
Disliked
Not to piggyback too much, but I have a question which I think may help both of us. Are you trying to get yours to modify more than one order when moving stoplosses? I can't get mine to reliably modify multiple orders and it always breaks down in the order selection process for me. Magnum, I'm definitely looking forward to seeing what you've got on the subject.

I'm going to go ahead and post the code I have for mine so far to see if there isn't anything overlapping between our problems.
Ignored
Yoda_Voice_Enabled = true;

Jedi, simple your problem is...

Yoda_Voice_Enabled = false;

LOL! Sorry not much sleep lately.

Remove the two return(0); statements from your for loop. Anytime your code makes it this far it will jump out of the start function and be done until the next candle. Just let it cascade down through the logic and then loop back for the next order in your list. Nice use of the global variables Jedi. Not many actually know about this unique feature to MT4.

Pip Parade: Can you either post your ea here by attaching it or PM it to me so I can look at the flow of the whole thing. I think I am missing something just looking at a snippet.
 
 
  • Post #7
  • Quote
  • Feb 15, 2008 3:20am Feb 15, 2008 3:20am
  •  magnumfreak
  • Joined Nov 2007 | Status: Trying manual mode again | 2,210 Posts
Ok, insert this statement prior to EACH of your OrderModify statements:

OrderSelect(glbOrderTicket,SELECT_BY_TICKET,MODE_TRADES);

I think what is happening is that the orderselect that you are using in your OrderFind function is local to that function. When you return to your main start function, the pointer is not coming with it. Since you determine what the ticketnumber is, just do another orderselect if the findorder function returns true.

Try this and let me know what results you get.
 
 
  • Post #8
  • Quote
  • Feb 15, 2008 11:14am Feb 15, 2008 11:14am
  •  Pip Parade
  • | Joined Dec 2007 | Status: ... often wrong but never in doubt | 222 Posts
Quoting magnumfreak
Disliked
Ok, insert this statement prior to EACH of your OrderModify statements:

OrderSelect(glbOrderTicket,SELECT_BY_TICKET,MODE_TRADES);
Ignored
Thanks magnumfreak ... Could you confirm in this sample below where exactly the code should be inserted?

--------

HERE??? if (glbOrderType==OP_BUY)
{//long open
if (Bid-glbOpenPrice>TargetMoveStopPipsA*Point && glbStopPrice<glbOpenPrice)Or Here???OrderModify(glbOrderTicket,
OrderOpenPrice(), NormalizeDouble(glbOpenPrice+StopMovePipsA*Point,Digits), OrderTakeProfit( ) , 0, Orange) ;
}

--------

I know it would have to also be inserted 3 more times.
 
 
  • Post #9
  • Quote
  • Feb 15, 2008 11:43am Feb 15, 2008 11:43am
  •  magnumfreak
  • Joined Nov 2007 | Status: Trying manual mode again | 2,210 Posts
first one. Prior to the start of the if statement would be fine.
 
 
  • Post #10
  • Quote
  • Feb 15, 2008 12:51pm Feb 15, 2008 12:51pm
  •  Pip Parade
  • | Joined Dec 2007 | Status: ... often wrong but never in doubt | 222 Posts
Thanks ...

I'll set it up so that it's ready to go when the market opens. The excitement will keep me awake all weekend.

Will let you know how it goes.
 
 
  • Post #11
  • Quote
  • Feb 15, 2008 1:04pm Feb 15, 2008 1:04pm
  •  Pip Parade
  • | Joined Dec 2007 | Status: ... often wrong but never in doubt | 222 Posts
Couldn't wait ...

Have done the following:
A) There was a space in the "SELECT_B Y_TICKET" part of the code. Compiler didn't like it so I eliminated it. Compiler is happy now.

B) Inserted code 2 times, not 4, so it looks like the 4 lines below.


if (OrderFind(magicno))
{//open order
OrderSelect(glbOrderTicket,SELECT_BY_TICKET,MODE_TRADES);
if (glbOrderType==OP_BUY)


Will activate for Sunday but may take 24 hours minimum for results.
 
 
  • Post #12
  • Quote
  • Feb 15, 2008 6:17pm Feb 15, 2008 6:17pm
  •  The Jedi
  • | Joined Mar 2007 | Status: A jedi seeks no title | 657 Posts
Hooray! It lives! Thanks magnumfreak.
Never underestimate the powers of the Force.
 
 
  • Post #13
  • Quote
  • Feb 15, 2008 6:34pm Feb 15, 2008 6:34pm
  •  Pip Parade
  • | Joined Dec 2007 | Status: ... often wrong but never in doubt | 222 Posts
Quoting magnumfreak
Disliked
Yoda_Voice_Enabled = true;
Ignored
Jedi, So was it a simple matter of reconnecting with the Force, or did you find yourself in battle with the Dark Side?
 
 
  • Post #14
  • Quote
  • Feb 15, 2008 8:07pm Feb 15, 2008 8:07pm
  •  The Jedi
  • | Joined Mar 2007 | Status: A jedi seeks no title | 657 Posts
Quoting Pip Parade
Disliked
Jedi, So was it a simple matter of reconnecting with the Force, or did you find yourself in battle with the Dark Side?
Ignored
I thought myself a master when I was still the student in this case. MT4 is not my strong point...yet...
Never underestimate the powers of the Force.
 
 
  • Post #15
  • Quote
  • Last Post: Feb 15, 2008 8:56pm Feb 15, 2008 8:56pm
  •  Pip Parade
  • | Joined Dec 2007 | Status: ... often wrong but never in doubt | 222 Posts
MT4 gets me as well. "Try many things I might if program I knew"

Until then, I'm hanging out on this board a lot.
 
 
  • Platform Tech
  • /
  • S/L won't adjust
  • Reply to Thread
0 traders viewing now
Top of Page
Forex Factory Blog Updated: Alerting All Members
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2022