Trendy Monster Moving Day

Maximilian
Trader
Posts: 149
Joined: Sat Sep 06, 2014 2:43 pm

Trendy Monster Moving Day

Post by Maximilian »

Hi Steve and all other coders,
I am kind of desperate at the moment. I adapted the code and this is what I try to do:
Like the original version I want Trendy Monster to open a grid, I added individual TP and SL for the grid. The first pending order, which actual triggers the grid shall close at the SL and then all grid orders shall be deleted. But it doesn´t work somehow. :arrrg: :arrrg: :arrrg:

Code: Select all

   if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT)
   
   {  
   if (OrderComment() == TradeComment) // initial trade, if it hits SL all orders get deleted
      
      {  
      //TP
      if (bid >= take && !closeEnough(take, 0) ) CloseThisTrade = true;
      //SL
      if (bid <= stop && !closeEnough(stop, 0) )
      {
   
      deletePendings = true;
      closeAllTrades(OrderSymbol(),OP_BUYSTOP);}
      CloseThisTrade = true;
      }  
    }// initial trade
Whenever the SL of the market trades got hit, the market order was deleted but the rest of the code doesn´t get processed and the pendings are still there. I doublechecked with Alert messages at diffferent spots in the code. Funny thing is, whenever I change for testing purposes "stop" with a double higher as the actual bid, the code works flawless and the market and all pendings get deleted. But not, when I use the stop variable, which is stop = OrdersStoploss(). Bug hunting is frustrating and time consuming, but I think I´ve got a misunderstanding of the function "lookingfortradeclosure". Any hints will be appreciated and thanks,
Maximilian
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.

Trendy Monster Moving Day

Post by SteveHopwood »

Maximilian » Sat May 15, 2021 2:22 pm wrote:Hi Steve and all other coders,
I am kind of desperate at the moment. I adapted the code and this is what I try to do:
Like the original version I want Trendy Monster to open a grid, I added individual TP and SL for the grid. The first pending order, which actual triggers the grid shall close at the SL and then all grid orders shall be deleted. But it doesn´t work somehow. :arrrg: :arrrg: :arrrg:

Code: Select all

   if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT)
   
   {  
   if (OrderComment() == TradeComment) // initial trade, if it hits SL all orders get deleted
      
      {  
      //TP
      if (bid >= take && !closeEnough(take, 0) ) CloseThisTrade = true;
      //SL
      if (bid <= stop && !closeEnough(stop, 0) )
      {
   
      deletePendings = true;
      closeAllTrades(OrderSymbol(),OP_BUYSTOP);}
      CloseThisTrade = true;
      }  
    }// initial trade
Whenever the SL of the market trades got hit, the market order was deleted but the rest of the code doesn´t get processed and the pendings are still there. I doublechecked with Alert messages at diffferent spots in the code. Funny thing is, whenever I change for testing purposes "stop" with a double higher as the actual bid, the code works flawless and the market and all pendings get deleted. But not, when I use the stop variable, which is stop = OrdersStoploss(). Bug hunting is frustrating and time consuming, but I think I´ve got a misunderstanding of the function "lookingfortradeclosure". Any hints will be appreciated and thanks,
Maximilian
This reminds me that biobier sent me a fix for something a few weeks ago. I thought to myself, "I will add the fix tomorrow," and forgot about it. :arrrg:

I will look at all this tomorrow. In the meantime, send me the entire function in a PM.

: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.
Maximilian
Trader
Posts: 149
Joined: Sat Sep 06, 2014 2:43 pm

Trendy Monster Moving Day

Post by Maximilian »

Hi Steve,
will do. But I don´t think it´s because of your code.
Cheers Max
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.

Trendy Monster Moving Day

Post by SteveHopwood »

Maximilian » Sat May 15, 2021 4:27 pm wrote:Hi Steve,
will do. But I don´t think it´s because of your code.
Cheers Max
What is your SendLimitOrder input?

: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.
Maximilian
Trader
Posts: 149
Joined: Sat Sep 06, 2014 2:43 pm

Trendy Monster Moving Day

Post by Maximilian »

I set ist to false. I just use stop Orders.
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.

Trendy Monster Moving Day

Post by SteveHopwood »

Maximilian » Sun May 16, 2021 10:14 am wrote:I set ist to false. I just use stop Orders.
I was hoping that would be your reply. :lol:

I will post a version with a fix for this and biobier's spot later, along with DIY instructions.

For your satisfaction Max, the void deleteOrphanPendings(string symbol, int pairIndex) is intended to deal with pending orders left behind by a market order closure. Go to it and work out for yourself why it is not working for you.

Incidentally, I do not see why your code is not working but it would not be needed but for the bloop in deleteOrphanPendings().

: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.
Maximilian
Trader
Posts: 149
Joined: Sat Sep 06, 2014 2:43 pm

Trendy Monster Moving Day

Post by Maximilian »

I got a brainfart and tell me if it´s wrong or intended:
Unless one uses HiddenSLTP the stop and take is stored in the OrderStopLoss() or OrderTakeProfit(). So there´s no code needed for closing the trade at TP or SL. Empty4 just closes the order no matter what. And after closing there is no market trade open, which would cause Trendy Monster to call the lookingforTradeclosure (because it´s called from COT routine) right? So question is, if I just misunderstood the purpose of the function this the routine. Is it just for trades where the SL or TP isn´t aleready saved in the order data, e.g HiddenSLTP or exit routines like reaching a SupplyDemand Zone?
Thanks,
Maximilian
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.

Trendy Monster Moving Day

Post by SteveHopwood »

V 1l is in post 1, with the fix offered up by biobier and my attempted fix for Max's stop orders not deleting.

The easiest way to DIY is to navigate to:
void deleteOrphanPendings(string symbol, int pairIndex)

Copy this over the top of the entire function:

Code: Select all

void deleteOrphanPendings(string symbol, int pairIndex)
{
   //A market trade that hits SL will leave stop orders behind, so delete them
   
   //Nothing open? Unlikely, but you never know
   if (openTrades == 0)
      return;
      
   //Market orders still open?
   if (marketTradesTotal > 0)
      return;
      
   //No pending trades?
   if (pendingTradesTotal == 0)
      return;
      
   //The initial stop and limit orders are still in place, so no deletion needed?
   if (buyStopOpen)
      if (!SendLimitOrder || buyLimitOpen)
         return;
   
   if (sellStopOpen)
      if (!SendLimitOrder || sellLimitOpen)
         return;
   
   /*
   The EA can know that a market order has hit SL when:
      - market orders = 0
      - stop orders > 0
      - the remaining stop orders are not hedged
   All these conditions were met for the code to get this far,
   so delete the remaining stop orders.   
   */       
   deletePendings = true;
   
   if (buyStopOpen)
      closeAllTrades(symbol, OP_BUYSTOP);
   if (buyLimitOpen)
      closeAllTrades(symbol, OP_BUYLIMIT);
      
   if (sellStopOpen)
      closeAllTrades(symbol, OP_SELLSTOP);
   if (sellLimitOpen)
      closeAllTrades(symbol, OP_SELLLIMIT);
      
   deletePendings = false;


}//End void deleteOrphanPendings(string symbol, int pairIndex)
: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.
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.

Trendy Monster Moving Day

Post by SteveHopwood »

Maximilian » Sun May 16, 2021 11:56 am wrote:I got a brainfart and tell me if it´s wrong or intended:
Unless one uses HiddenSLTP the stop and take is stored in the OrderStopLoss() or OrderTakeProfit(). So there´s no code needed for closing the trade at TP or SL. Empty4 just closes the order no matter what. And after closing there is no market trade open, which would cause Trendy Monster to call the lookingforTradeclosure (because it´s called from COT routine) right? So question is, if I just misunderstood the purpose of the function this the routine. Is it just for trades where the SL or TP isn´t aleready saved in the order data, e.g HiddenSLTP or exit routines like reaching a SupplyDemand Zone?
Thanks,
Maximilian
lookForTradeClosure() is only called for open market orders.

I am not sure that Trendy can do what you require but try it with the fixes.

You can also try the attached management EA. I was experimenting with sending stop instead of limit orders using Richard's TDesk setup and stop orders were being left behind if a market order(s) hit stop loss. The attached manager takes care of this.

The GridSize input needs to be the same as Trendy's if you are only sending stop orders. It needs to be Trendy's grid size + 1 if you are sending an immediate market order.

:xm: :rocket:
You do not have the required permissions to view the files attached to this post.
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.
Maximilian
Trader
Posts: 149
Joined: Sat Sep 06, 2014 2:43 pm

Trendy Monster Moving Day

Post by Maximilian »

Thank you very much Steve, :clap: :)
I will try all the options and hopefully find a solution,
Greetings,
Maximilian
Post Reply

Return to “Trendy Monster Moving Day”