Coding help - page 733

 
tfi_markets:

Hi Pro-Coders,

I wonder if someone could help,

I would like to my EA open a Buy Trade and close an existing Sell Trade on trend change.

It does it, but only when it took profit. When the trend changes while the position is still

open, it runs in StopLoss. (See picture). Sometimes is it working and sometimes not.

What could I improve? 

 

if(trendNow!=trendPrev)
         if(trendNow>0 && (NLD1>NLD2) && RSIfilter>55)
           {
            OpenBuy_  =true;
            CloseSell_=true;
           }
         else
         if(trendPrev>0 && (NLD1<NLD2) && RSIfilter<45)
           {
            OpenSell_=true;
            CloseBuy_=true;  
          }
That code part is not enough to conclude anything
 
mladen:
That code part is not enough to conclude anything

Hi Mladen,

thank you very much for having a look into my issue.

Please find the code below which shall close existing Sell and Buy orders.

It also should open a new Buy or Sell order if the trend points towards the right direction... 

//+------------------------------------------------------------------+
//| Signal Exit Buy / Exit Sell)                                          
//| Iterate through open tickets
//+------------------------------------------------------------------+

   for(int i=0; i<Total; i++)
     {
      dummyResult=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
        {
         if(OrderType()==OP_BUY && OrderMagicNumber()==MagicNumber)
           {

            for(int z=OrdersTotal()-1; z>=0; z--)
              {
               if(OrderSelect(z,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol())
                 {
                  if(OrderType()==OP_BUY)
                     buy_ticket=OrderTicket();
                  else
                  if(OrderType()== OP_SELL)
                     sell_ticket=OrderTicket();
                 }

// Close BUY

               if(CloseBuy_==true && buy_ticket!=0)
                 {
                  dummyResult=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage*PipMultiplier,MediumSeaGreen);
                  if(EachTickMode) TickCheck = True;
                  if(!EachTickMode) BarCount = Bars;
                  Print("Error closing Buy #",(string)OrderTicket()," Error code ",(string)GetLastError());

// Open new Sell Order 

if(trendPrev>0 && (NLD1<NLD2) && RSIfilter<45) OpenSell_=true;                

 }


// Close SELL
               if(CloseSell_==true && sell_ticket!=0)
                 {
                  dummyResult=OrderClose(OrderTicket(),OrderLots(),Ask,Slippage*PipMultiplier,DarkOrange);
                  if(EachTickMode) TickCheck = True;
                  if(!EachTickMode) BarCount = Bars;
                  Print("Error closing Sell #",(string)OrderTicket()," Error code ",(string)GetLastError());


// Open new Buy Order                

if(trendNow>0 && (NLD1>NLD2) && RSIfilter>55) OpenBuy_  =true

 

}
              }
 
tfi_markets:

Hi Mladen,

thank you very much for having a look into my issue.

Please find the code below which shall close existing Sell and Buy orders.

It also should open a new Buy or Sell order if the trend points towards the right direction... 

//+------------------------------------------------------------------+
//| Signal Exit Buy / Exit Sell)                                          
//| Iterate through open tickets
//+------------------------------------------------------------------+

   for(int i=0; i<Total; i++)
     {
      dummyResult=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
        {
         if(OrderType()==OP_BUY && OrderMagicNumber()==MagicNumber)
           {

            for(int z=OrdersTotal()-1; z>=0; z--)
              {
               if(OrderSelect(z,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol())
                 {
                  if(OrderType()==OP_BUY)
                     buy_ticket=OrderTicket();
                  else
                  if(OrderType()== OP_SELL)
                     sell_ticket=OrderTicket();
                 }

// Close BUY

               if(CloseBuy_==true && buy_ticket!=0)
                 {
                  dummyResult=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage*PipMultiplier,MediumSeaGreen);
                  if(EachTickMode) TickCheck = True;
                  if(!EachTickMode) BarCount = Bars;
                  Print("Error closing Buy #",(string)OrderTicket()," Error code ",(string)GetLastError());

// Open new Sell Order 

if(trendPrev>0 && (NLD1<NLD2) && RSIfilter<45) OpenSell_=true;                

 }


// Close SELL
               if(CloseSell_==true && sell_ticket!=0)
                 {
                  dummyResult=OrderClose(OrderTicket(),OrderLots(),Ask,Slippage*PipMultiplier,DarkOrange);
                  if(EachTickMode) TickCheck = True;
                  if(!EachTickMode) BarCount = Bars;
                  Print("Error closing Sell #",(string)OrderTicket()," Error code ",(string)GetLastError());


// Open new Buy Order                

if(trendNow>0 && (NLD1>NLD2) && RSIfilter>55) OpenBuy_  =true

 

}
              }
Why are you using a loop within the loop? No need for that at all. Get rid of it, and when the code is simplified, all will be easier to clean up too
 
pls i need someone to help me make an EA OF THIS INDICATOR 
 
mladen:
Why are you using a loop within the loop? No need for that at all. Get rid of it, and when the code is simplified, all will be easier to clean up too

Hi Mladen,

I have modified the code accordingly, do you think it's better now?

Could you please have a look? This code is still in an pseudo state, not tested yet.

Thank you in advance!

//+-------------------------------------------------------------------------+
//| Signal close Buy / close Sell / Open new BUY or SELL order when possible   

int PositionIndex;    
int TotalNumberOfOrders;  
TotalNumberOfOrders = OrdersTotal();// store number of Orders in the variable

for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)// for loop to loop through all Orders . .   COUNT DOWN TO ZERO !
   {
   if(!OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES)) continue;// if the OrderSelect fails advance the loop to the next PositionIndex
  
if(OrderMagicNumber() == MagicNumber   // does the Order's Magic Number match our EA's magic number ?
   && OrderSymbol() == Symbol()         // does the Order's Symbol match the Symbol our EA is working on ?
   && (OrderType() == OP_BUY           // is the Order a Buy Order ?
   || OrderType() == OP_SELL ))      // or is it a Sell Order ?
  
 if (! OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), Slippage*PipMultiplier,DarkOrange )) //try to close the order
  Print("Order Close failed, order number: ", OrderTicket(), " Error: ", GetLastError()); //if the Order Close failed print some helpful information
              
     if(trendNow>0 && (NLD1>NLD2) && RSIfilter>52) // Check if new entry condition is given
           {
            OpenBuy_=true;
             }
         else
     if(trendPrev>0 && (NLD1<NLD2) && RSIfilter<42)
           {
            OpenSell_=true;
              }
   } // end of For loop        
  
 
tfi_markets:

Hi Mladen,

I have modified the code accordingly, do you think it's better now?

Could you please have a look? This code is still in an pseudo state, not tested yet.

Thank you in advance!

//+-------------------------------------------------------------------------+
//| Signal close Buy / close Sell / Open new BUY or SELL order when possible   

int PositionIndex;    
int TotalNumberOfOrders;  
TotalNumberOfOrders = OrdersTotal();// store number of Orders in the variable

for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)// for loop to loop through all Orders . .   COUNT DOWN TO ZERO !
   {
   if(!OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES)) continue;// if the OrderSelect fails advance the loop to the next PositionIndex
  
if(OrderMagicNumber() == MagicNumber   // does the Order's Magic Number match our EA's magic number ?
   && OrderSymbol() == Symbol()         // does the Order's Symbol match the Symbol our EA is working on ?
   && (OrderType() == OP_BUY           // is the Order a Buy Order ?
   || OrderType() == OP_SELL ))      // or is it a Sell Order ?
  
 if (! OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), Slippage*PipMultiplier,DarkOrange )) //try to close the order
  Print("Order Close failed, order number: ", OrderTicket(), " Error: ", GetLastError()); //if the Order Close failed print some helpful information
              
     if(trendNow>0 && (NLD1>NLD2) && RSIfilter>52) // Check if new entry condition is given
           {
            OpenBuy_=true;
             }
         else
     if(trendPrev>0 && (NLD1<NLD2) && RSIfilter<42)
           {
            OpenSell_=true;
              }
   } // end of For loop        
  
Yes. much better :)
 

Mntiwana

Here is the EA for B& S with 15 warnings left. If some one could tell me how to clear Declaration of global  such as “declaration of 'trailingprofit' hides global declaration at line 62  mnt-BuyersSellers EA v1.00.mq4              915         53” I will clear it up.

I also need a few files to run it.

2016.12.17 16:01:35.347 2016.11.01 00:47  cannot open file 'C:\FXPrograms\Tallinex\MQL4\indicators\4BARS-MTF-BBH 1.06.ex4' [2]

2016.12.17 16:01:29.815 2016.11.01 00:17  cannot open file 'C:\FXPrograms\Tallinex\MQL4\indicators\BullBearHelper 1.00.ex4' [2]

2016.12.17 16:01:29.815 2016.11.01 00:17  cannot open file 'C:\FXPrograms\Tallinex\MQL4\indicators\AdaptiveLaguerreFilter.ex4' [2]

And ,"Slope Direction Line"

Let me Know

Ray

 
traderduke:

traderduke

Thanks for your interest,indi package is attached,actually the whole system is from FF (http://www.tradingsystemforex.com/ideas-for-expert-advisors/4662-buyers-sellers-ea.html)

gspe was working on it but i think the whole EA frame is from "funyoo" and i am only interested in EA code as sample/model frame to create some new EA with,the rest of their strategy is not fruit full as per my guess,we can form better than of that,we have 100 times better indicators for now :)

regards

Files:
package.zip  59 kb
 
traderduke:
And if we add "t" before that of (declaration of ..... hide global declaration) all warnings will be removed but i am not sure is it correct ? ..... i get this tip from the thread (https://www.forex-tsd.com/forum/debates-discussions/18543-ea-not-working-under-build-610) and long two page cross conversation/argu in between

"crsnapebtinternetcom" and  MLADEN ..... then i test and it worked but needs some certification :)

regards

 
mntiwana:

traderduke

Thanks for your interest,indi package is attached,actually the whole system is from FF (http://www.tradingsystemforex.com/ideas-for-expert-advisors/4662-buyers-sellers-ea.html)

gspe was working on it but i think the whole EA frame is from "funyoo" and i am only interested in EA code as sample/model frame to create some new EA with,the rest of their strategy is not fruit full as per my guess,we can form better than of that,we have 100 times better indicators for now :)

regards

Guys

Funyoos EAs usually showed good results when using martingale on back test. I would be very careful when using them

Reason: