MPTM updated

MPTM's new home
Post Reply
Fourxxxx

MPTM updated

Post by Fourxxxx »

SteveHopwood » Tue Dec 15, 2020 5:39 am wrote: You are talking about the likes of SS and HGI as included with MPTM?

:xm: :rocket:
Yes that is correct ie if I use your HGI scripts it opens many pending trades and the market may not reach all of them. So if an indicator closes a trade it would be useful to delete the remaining pending orders also.
danjuma
Trader
Posts: 68
Joined: Mon Jun 10, 2013 4:14 pm

MPTM updated

Post by danjuma »

There are two exactly named MPTM mq4 files attached to post 1, are they the same or different in some ways?
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

MPTM updated

Post by SteveHopwood »

danjuma » Wed Dec 16, 2020 9:03 pm wrote:There are two exactly named MPTM mq4 files attached to post 1, are they the same or different in some ways?
No idea how that happened. They both have 1d as their version.

I will be posting an update soon so you will know you have the latest version if you download the update.

:xm: :rocket:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
danjuma
Trader
Posts: 68
Joined: Mon Jun 10, 2013 4:14 pm

MPTM updated

Post by danjuma »

SteveHopwood » Thu Dec 17, 2020 10:16 am wrote:
danjuma » Wed Dec 16, 2020 9:03 pm wrote:There are two exactly named MPTM mq4 files attached to post 1, are they the same or different in some ways?
No idea how that happened. They both have 1d as their version.

I will be posting an update soon so you will know you have the latest version if you download the update.

:xm: :rocket:

Thank you Steve. And a merry Xmas to you (in which ever form that takes for you in this Covid, lock-down and tiers times!)
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

MPTM updated

Post by SteveHopwood »

V 1e is in post 1.

The HGI/SS/MA closure functions were only looking at market trades, which is why the stop and limit orders were ignored. This should be fixed now.

To DIY to preserve you hard coded inputs, go to the bool ShouldThisTradeBeClosed(int ticket) function. The next three functions down are:
  • bool UsingBobMaForTradeClosing(int ticket)
  • bool UsingHgiToCloseTrade(int ticket)
  • bool UsingSuperSlopeToCloseThisTrade(int ticket)
Go to each function and scroll down to:
if (OrderType() == OP_BUY)
Add the stop/limit order conditionals so that the line of code becomes:
if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT)

Then scroll down to:
if (OrderType() == OP_SELL)
Change it to:
if (OrderType() == OP_SELL || OrderType() == OP_SELLSTOP || OrderType() == OP_SELLLIMIT)

Thanks for pointing this out danjuma.

:xm: :rocket:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
Fourxxxx

MPTM updated

Post by Fourxxxx »

My coding skills are limited so please understand.

I am trying to get MPTM to close trades using the MA but only to become active after the trade has moved into profit. This because with the system I am using the price is often on the wrong side of the MA at entry. Without modification, MPTM would close these trades at entry.

This is what I have tried but it is not always closing trades when the close is on the wrong side of the MA and in profit.

Code: Select all

bool UsingBobMaForTradeClosing(int ticket)
{

   //Returns 'true' if the previous candle closed on the wrong side of the MA for the trade, else 'false'

   if (!BetterOrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES) )
      return(false);

   //No need to read the previous candle at every timer event
   static datetime OldBarTime = 0;
   if (OldBarTime != iTime(OrderSymbol(), MaTFC, 0) )
   {
      OldBarTime = iTime(OrderSymbol(), MaTFC, 0);
         
      double val = GetMa(OrderSymbol(), MaTFC, MaPeriodC, MaShiftC, MaMethodC, MaAppliedPriceC, 1);
      
      if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT)

        if (iClose(OrderSymbol(), MaTFC, 1) >= OrderOpenPrice()) //FourXXXX
         if (iClose(OrderSymbol(), MaTFC, 1) < val)
            return(true);
   
      if (OrderType() == OP_SELL || OrderType() == OP_SELLSTOP || OrderType() == OP_SELLLIMIT)
        if (iClose(OrderSymbol(), MaTFC, 1) <= OrderOpenPrice()) //FourXXX
         if (iClose(OrderSymbol(), MaTFC, 1) > val)
            return(true);

   }//if (OldBarTime != iTime(OrderSymbol(), SsTimeFrameC, 0) )

       
   //Got this far, so no closure needed
   return(false);      

}//End bool UsingBobMaForTradeClosing(int ticket)
This line if (iClose(OrderSymbol(), MaTFC, 1) >= OrderOpenPrice()) //FourXXXX is intended to stop the closure happening unless the trade is on the profit side of the open.

Any tips appreciated and sorry if this causes any bother.
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

MPTM updated

Post by SteveHopwood »

Fourxxxx » Fri Jan 08, 2021 7:17 am wrote:My coding skills are limited so please understand.

I am trying to get MPTM to close trades using the MA but only to become active after the trade has moved into profit. This because with the system I am using the price is often on the wrong side of the MA at entry. Without modification, MPTM would close these trades at entry.

This is what I have tried but it is not always closing trades when the close is on the wrong side of the MA and in profit.

Code: Select all

bool UsingBobMaForTradeClosing(int ticket)
{

   //Returns 'true' if the previous candle closed on the wrong side of the MA for the trade, else 'false'

   if (!BetterOrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES) )
      return(false);

   //No need to read the previous candle at every timer event
   static datetime OldBarTime = 0;
   if (OldBarTime != iTime(OrderSymbol(), MaTFC, 0) )
   {
      OldBarTime = iTime(OrderSymbol(), MaTFC, 0);
         
      double val = GetMa(OrderSymbol(), MaTFC, MaPeriodC, MaShiftC, MaMethodC, MaAppliedPriceC, 1);
      
      if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT)

        if (iClose(OrderSymbol(), MaTFC, 1) >= OrderOpenPrice()) //FourXXXX
         if (iClose(OrderSymbol(), MaTFC, 1) < val)
            return(true);
   
      if (OrderType() == OP_SELL || OrderType() == OP_SELLSTOP || OrderType() == OP_SELLLIMIT)
        if (iClose(OrderSymbol(), MaTFC, 1) <= OrderOpenPrice()) //FourXXX
         if (iClose(OrderSymbol(), MaTFC, 1) > val)
            return(true);

   }//if (OldBarTime != iTime(OrderSymbol(), SsTimeFrameC, 0) )

       
   //Got this far, so no closure needed
   return(false);      

}//End bool UsingBobMaForTradeClosing(int ticket)
This line if (iClose(OrderSymbol(), MaTFC, 1) >= OrderOpenPrice()) //FourXXXX is intended to stop the closure happening unless the trade is on the profit side of the open.

Any tips appreciated and sorry if this causes any bother.
I don't know if this will help but what I would do is:
  • Insert a check that the order is in profit underneath the BetterOrderSelect.
  • Remove the unwanted conditionals for OP_BUYSTOP etc.
  • Remove the if (iClose(OrderSymbol(), MaTFC, 1) >= OrderOpenPrice()) //FourXXXX from the two blocks.
Like this:

Code: Select all

bool UsingBobMaForTradeClosing(int ticket)
{

   //Returns 'true' if the previous candle closed on the wrong side of the MA for the trade, else 'false'

   if (!BetterOrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES) )
      return(false);
      
   //Only close profitable orders  
   if ((OrderProfit() + OrderSwap() + OrderCommission()) < 0 )
      return(false);  

   //No need to read the previous candle at every timer event
   static datetime OldBarTime = 0;
   if (OldBarTime != iTime(OrderSymbol(), MaTFC, 0) )
   {
      OldBarTime = iTime(OrderSymbol(), MaTFC, 0);
         
      double val = GetMa(OrderSymbol(), MaTFC, MaPeriodC, MaShiftC, MaMethodC, MaAppliedPriceC, 1);
      
      if (OrderType() == OP_BUY)
        if (iClose(OrderSymbol(), MaTFC, 1) < val)
            return(true);
   
      if (OrderType() == OP_SELL)
        if (iClose(OrderSymbol(), MaTFC, 1) > val)
            return(true);

   }//if (OldBarTime != iTime(OrderSymbol(), SsTimeFrameC, 0) )

       
   //Got this far, so no closure needed
   return(false);      

}//End bool UsingBobMaForTradeClosing(int ticket)
The reason I am not sure this helps is that I cannot see why your adaptation is not working.

We always think it is the code we added that is at fault, but sometimes the problem lies elsewhere. Go to the void OnTimer() function and make sure none of your inputs are causing the function to abort before reaching the DoTradeManagement(); call.

:xm: :rocket:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
Fourxxxx

MPTM updated

Post by Fourxxxx »

SteveHopwood » Fri Jan 08, 2021 9:56 pm wrote:
I don't know if this will help but what I would do is:
  • Insert a check that the order is in profit underneath the BetterOrderSelect.
  • Remove the unwanted conditionals for OP_BUYSTOP etc.
  • Remove the if (iClose(OrderSymbol(), MaTFC, 1) >= OrderOpenPrice()) //FourXXXX from the two blocks.
Like this:

Code: Select all

bool UsingBobMaForTradeClosing(int ticket)
{

   //Returns 'true' if the previous candle closed on the wrong side of the MA for the trade, else 'false'

   if (!BetterOrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES) )
      return(false);
      
   //Only close profitable orders  
   if ((OrderProfit() + OrderSwap() + OrderCommission()) < 0 )
      return(false);  

   //No need to read the previous candle at every timer event
   static datetime OldBarTime = 0;
   if (OldBarTime != iTime(OrderSymbol(), MaTFC, 0) )
   {
      OldBarTime = iTime(OrderSymbol(), MaTFC, 0);
         
      double val = GetMa(OrderSymbol(), MaTFC, MaPeriodC, MaShiftC, MaMethodC, MaAppliedPriceC, 1);
      
      if (OrderType() == OP_BUY)
        if (iClose(OrderSymbol(), MaTFC, 1) < val)
            return(true);
   
      if (OrderType() == OP_SELL)
        if (iClose(OrderSymbol(), MaTFC, 1) > val)
            return(true);

   }//if (OldBarTime != iTime(OrderSymbol(), SsTimeFrameC, 0) )

       
   //Got this far, so no closure needed
   return(false);      

}//End bool UsingBobMaForTradeClosing(int ticket)
The reason I am not sure this helps is that I cannot see why your adaptation is not working.

We always think it is the code we added that is at fault, but sometimes the problem lies elsewhere. Go to the void OnTimer() function and make sure none of your inputs are causing the function to abort before reaching the DoTradeManagement(); call.

:xm: :rocket:
Thanks Steve, I have your suggestions running now on test. If it works it will still sometimes be closing trades at near the open as my entry trigger is often several pips on the wrong side of the MA 5 with shift of 2. Might be easier for me to just write an EA to go on each chart to handle the MA cross close.
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

MPTM updated

Post by SteveHopwood »

Fourxxxx » Fri Jan 08, 2021 12:37 pm wrote:
Thanks Steve, I have your suggestions running now on test. If it works it will still sometimes be closing trades at near the open as my entry trigger is often several pips on the wrong side of the MA 5 with shift of 2. Might be easier for me to just write an EA to go on each chart to handle the MA cross close.
You need to compare the close at shift 2 with the close at shift 1 to detect a cross.

Code: Select all

bool UsingBobMaForTradeClosing(int ticket)
{
 
   //Returns 'true' if the previous candle closed on the wrong side of the MA for the trade, else 'false'
 
   if (!BetterOrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES) )
      return(false);
     
   //Only close profitable orders  
   if ((OrderProfit() + OrderSwap() + OrderCommission()) < 0 )
      return(false);  
 
   string symbol = OrderSymbol() );//Makes typing easier
 
   //No need to read the previous candle at every timer event
   static datetime OldBarTime = 0;
   if (OldBarTime != iTime(OrderSymbol(), MaTFC, 0) )
   {
      OldBarTime = iTime(OrderSymbol(), MaTFC, 0);
         
      double val1 = GetMa(OrderSymbol(), MaTFC, MaPeriodC, MaShiftC, MaMethodC, MaAppliedPriceC, 1);
      double val2 = GetMa(OrderSymbol(), MaTFC, MaPeriodC, MaShiftC, MaMethodC, MaAppliedPriceC, 2);
     
      //Look for a short cross
      if (OrderType() == OP_BUY)
        if (iClose(symbol, MaTFC, 2) > val2 )
          if (iClose(symbol, MaTFC, 1) < val1 )        
            return(true);
   
      //Look for a long cross
      if (OrderType() == OP_SELL)
        if (iClose(symbol, MaTFC, 2) < val2 )
          if (iClose(symbol, MaTFC, 1) > val1 )        
            return(true);
 
   }//if (OldBarTime != iTime(OrderSymbol(), SsTimeFrameC, 0) )
 
       
   //Got this far, so no closure needed
   return(false);      
 
}//End bool UsingBobMaForTradeClosing(int ticket)
Needing the order to be in profit before closing would negate the MA cross and so would never result in the order closing.

:xm: :rocket:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
Fourxxxx

MPTM updated

Post by Fourxxxx »

Thank you Steve, I see now my original logic was flawed, to me it looks like the code you wrote would act as per the image, which is exactly what I am trying to achieve.
MA Cross Close.jpg
A buy at the yellow circle (which is an actual trade I entered) would close in profit at the red circled close after previously closing above the red MA then closing below it if I am understanding the code correctly. Now I will have to wait till Monday to see how it goes.
You do not have the required permissions to view the files attached to this post.
Post Reply

Return to “Utilities Indicators and Scripts”