Best Bob

Post your 10.7 EA's here
Post Reply
phil_trade

Best Bob

Post by phil_trade »

Steve

I have improve my Unique Magic Generator to allow Empty4 switch down/up and recover the same MN

init() should be change with :

Code: Select all

  // Test pour éviter même magicNumber sur Chaque Symbol
   int UniqueMagicNumber = ReturnMagicNumberOfOpenTrade();
   
   if (UniqueMagicNumber == 0)
   {
   UniqueMagicNumber = WindowHandle(Symbol(),0);
   TrendMagicNumber = UniqueMagicNumber;
   CtMagicNumber    = UniqueMagicNumber+1;
   }
   else
   {
   TrendMagicNumber = UniqueMagicNumber;
   CtMagicNumber    = UniqueMagicNumber+1;
   }

   if (TrendMagicNumber == 0)  TrendMagicNumber=837746;
   if (CtMagicNumber == 0)  TrendMagicNumber=837747;
   
   Alert(Symbol()+" MN Trend = "+TrendMagicNumber+" MN CT Trend = "+CtMagicNumber);
and new function to be added :

Code: Select all

int ReturnMagicNumberOfOpenTrade()
{

   if (OrdersTotal() == 0) return(0);
   
   for (int cc = OrdersTotal() - 1; cc >= 0; cc--)
   {
      if (!OrderSelect(cc, SELECT_BY_POS, MODE_TRADES) ) continue;
      if (OrderSymbol() != Symbol() ) continue;
      
      return(OrderMagicNumber());
   }  //for (int cc = OrdersTotal() - 1; cc >= 0; cc--)  
   return(0);
} // int ReturnMagicNumberOfOpenTrade(MySymbol : string)
This assure a unique Magic Number for each pair.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Best Bob

Post by SteveHopwood »

Thanks for some really helpful posts guys. :clap: I had time to think about all this when driving to and from the hospital. Here is what I shall do after something to eat.
  • store the value of OrdersTotal() before firing the loop
  • exit the loop and entire function if the saved value and OrdersTotal() mismatch.
  • turn CountOpenTrades() into a boolean that returns true if the loop runs smoothly, or false if not. That way, start() will know whether to continue to run or to abort and await the next tick.
:xm:
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. pianodoodler@hotmail.com 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: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Best Bob

Post by SteveHopwood »

V 1c is in post 1, with the changes I described in my previous post.

To hand-code these changes, copy this over your existing CountOpenTrades() function:

Code: Select all

bool CountOpenTrades()
{
   //Not all these will be needed. Which ones are depends on the individual EA.
   OpenTrades = 0;
   TicketNo = -1;
   BuyOpen = false;
   SellOpen = false;
   PendingBuyOpen = false;
   PendingSellOpen = false;
   int type;//Saves the OrderType() for consulatation later in the function
   TradeHasPartClosed=false;
   
   upl = 0;//Unrealised profit and loss for hedging/recovery basket closure decisions

   if (OrdersTotal() == 0) return(true);
   
   //Define a variable to avoid the situation that Phil describes at http://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=92449#p92449
   double ot = OrdersTotal();
   
   //Iterating backwards through the orders list caters more easily for closed trades than iterating forwards
   for (int cc = OrdersTotal() - 1; cc >= 0; cc--)
   {
      if (ot != OrdersTotal() )
         return(false);
         
      bool TradeWasClosed = false;//See 'check for possible trade closure'

      //Ensure the trade is still open
      if (!OrderSelect(cc, SELECT_BY_POS, MODE_TRADES) ) continue;
      //Ensure the EA 'owns' this trade
      if (OrderSymbol() != Symbol() ) continue;
      if (OrderMagicNumber() != TrendMagicNumber) 
         if (OrderMagicNumber() != CtMagicNumber) 
            continue;
      if (OrderCloseTime() > 0) continue; 
      
      //All conditions passed, so carry on
      type = OrderType();//Store the order type
      
      OpenTrades++;
      //Store the latest trade sent. Most of my EA's only need this final ticket number as either they are single trade
      //bots or the last trade in the sequence is the important one. Adapt this code for your own use.
      if (TicketNo  == -1) TicketNo = OrderTicket();
      
      //upl might not be needed. Depends on the individual EA
      upl+= (OrderProfit() + OrderSwap() + OrderCommission()); 
      //The next line of code calculates the pips upl of an open trade. As yet, I have done nothing with it.
      //something = CalculateTradeProfitInPips()
      
      //These might need extra coding if both stop and limit orders are used
      if (OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT) PendingBuyOpen = true;
      if (OrderType() == OP_SELLSTOP || OrderType() == OP_SELLLIMIT) PendingSellOpen = true;
      //Add missing tp/sl in case rapidly moving markets prevent their addition - ECN
      if (CloseEnough(OrderStopLoss(), 0) && !CloseEnough(StopLoss, 0)) InsertStopLoss(OrderTicket());
      if (CloseEnough(OrderTakeProfit(), 0) && !CloseEnough(TakeProfit, 0)) InsertTakeProfit(OrderTicket() );

      //Replace missing tp and sl lines
      if (HiddenPips > 0) ReplaceMissingSlTpLines();
      
      
      TradeWasClosed = LookForTradeClosure(OrderTicket() );
      if (TradeWasClosed) 
      {
         if (type == OP_BUY) BuyOpen = false;//Will be reset if subsequent trades are buys that are not closed
         if (type == OP_SELL) SellOpen = false;//Will be reset if subsequent trades are sells that are not closed
         cc++;
         continue;
      }//if (TradeWasClosed) 
         
      //Profitable trade management
      if (OrderProfit() > 0) 
      {
         TradeManagementModule();
         if (TradeHasPartClosed) continue;//Part-closing changes the ticket number, so we cannot continue the current loop iteration
      }//if (OrderProfit() > 0) 
            
      //Trade types and half-close, and adjust sl/tp in case slippage has caused them to be inaccurate when the trade was sent.
      if (OrderType() == OP_BUY) 
      {
         BuyOpen = true;
         if (PartCloseEnabled && OrderComment() == TradeComment && OrderStopLoss() >= OrderOpenPrice() ) PartCloseTrade(OrderTicket() );
      }//if (OrderType() == OP_BUY) 
      
      if (OrderType() == OP_SELL) 
      {
         SellOpen = true;
         if (PartCloseEnabled && OrderComment() == TradeComment && OrderStopLoss() <= OrderOpenPrice()  && !CloseEnough(OrderStopLoss(), 0)) PartCloseTrade(OrderTicket() );
      }//if (OrderType() == OP_SELL) 
      
   }//for (int cc = OrdersTotal() - 1; cc <= 0; c`c--)
   
   //Loop exited correctly, so tell the rest of the code
   return(true);
   
}//End bool CountOpenTrades();
Then go to start() and replace the call to CountOpenTrades() with:

Code: Select all

if (!CountOpenTrades() )
      return(0);
There is a call to CountOpenTrades in init() as well, but it doesn't matter if that call fails the OrdersHistory() test.

I reckon that anyone using my shells needs to implement these changes across their files.

:xm:
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. pianodoodler@hotmail.com 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.
Haggadah
Trader
Posts: 154
Joined: Sat Dec 03, 2011 12:01 pm

Demo Account and Live, need help

Post by Haggadah »

I opened a demo account and downloaded the EA. I was wondering how I could be able to detach the EA from my live account because each time I log-on back to my live account, the EA from my demo is there. There must be a way to refresh but I cannot figure it out. Any help is very much appreciated.

Haggadah
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

Demo Account and Live, need help

Post by milanese »

Haggadah » Tue May 27, 2014 11:15 am wrote:I opened a demo account and downloaded the EA. I was wondering how I could be able to detach the EA from my live account because each time I log-on back to my live account, the EA from my demo is there. There must be a way to refresh but I cannot figure it out. Any help is very much appreciated.

Haggadah
You should use seperate Empty4 installations for your live and your demo account, just install your demo(or your live) account in an other directory..

Cheers :)

Tommaso
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
Haggadah
Trader
Posts: 154
Joined: Sat Dec 03, 2011 12:01 pm

Demo Account and Live, need help

Post by Haggadah »

milanese » Tue May 27, 2014 12:18 pm wrote:
Haggadah » Tue May 27, 2014 11:15 am wrote:I opened a demo account and downloaded the EA. I was wondering how I could be able to detach the EA from my live account because each time I log-on back to my live account, the EA from my demo is there. There must be a way to refresh but I cannot figure it out. Any help is very much appreciated.

Haggadah
You should use seperate Empty4 installations for your live and your demo account, just install your demo(or your live) account in an other directory..

Cheers :)

Tommaso
Thank you Tommaso, I will do that.

Haggadah
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Demo Account and Live, need help

Post by SteveHopwood »

Haggadah » Tue May 27, 2014 11:15 am wrote:I opened a demo account and downloaded the EA. I was wondering how I could be able to detach the EA from my live account because each time I log-on back to my live account, the EA from my demo is there. There must be a way to refresh but I cannot figure it out. Any help is very much appreciated.

Haggadah
Ouch. Never ever, ever, ever, ever, ever mix your live with your demo account on the same platform - quintuply so when your demo is running an EA. The potential for cataclysmic disaster in colossal. :o

Next time you are tempted to do so, get someone to beat you over the head with something heavy. :D

:xm:
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. pianodoodler@hotmail.com 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
patmontes
Trader
Posts: 367
Joined: Wed Apr 23, 2014 10:42 pm

Best Bob

Post by patmontes »

Giving this a spin today on 4H. Yellow line flip turned off and TMA exit to true.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Best Bob

Post by SteveHopwood »

patmontes » Mon Aug 11, 2014 1:08 pm wrote:Giving this a spin today on 4H. Yellow line flip turned off and TMA exit to true.
I wouldn't bother if I were you? Notice the quiet around here lately? There is a reason.

:xm:
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. pianodoodler@hotmail.com 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
patmontes
Trader
Posts: 367
Joined: Wed Apr 23, 2014 10:42 pm

Best Bob

Post by patmontes »

SteveHopwood » Mon Aug 11, 2014 9:20 pm wrote:
patmontes » Mon Aug 11, 2014 1:08 pm wrote:Giving this a spin today on 4H. Yellow line flip turned off and TMA exit to true.
I wouldn't bother if I were you? Notice the quiet around here lately? There is a reason.

:xm:
Hmmm yes.... all too quiet...
I guess best if i trade it manual then on D1
Post Reply

Return to “10.7 Auto Traders Forum”