Coding help - page 705

 


double BU1=iMA(Symbol(),0,ShortSma,0,MODE_SMA,PRICE_CLOSE,i+1);
     
 double BL1=iMA(Symbol(),0,LongSma,0,MODE_SMA,PRICE_CLOSE,i);

string SBUY="false";string SSEL="false";

if(BU1<Close[1]&&BL1<Close[1])SBUY="true";if(BL1>Close[1]&&BU1>Close[1])SSEL="true";

It works now, something was wrong with Trade after TP.....

Thank you for your Help Mladen.

 

hello mr mladen

how could translate this word:

 http://forexsystemsru.com/1075962-post327.html

Cluster analysis


regard 


 

 

 

mr mladen:

could you make MTF of it

best regard

 

Hi dear coders,

 

I have probably a simple question, but I stuck at the moment on:

My EA is opening and buy and sell orders without problem, but when it comes

to  SIGNAL_CLOSEBUY or SIGNAL_CLOSESELL it doesn't close the orders.

Here I use an RSI_Filter as trigger to close buy or sell orders. 

 I have  copied my code in, I would be very happy if someone could have a look.

Thank you in advance!

 

#define SIGNAL_NONE      0
#define SIGNAL_BUY       1
#define SIGNAL_SELL      2
#define SIGNAL_CLOSEBUY  3
#define SIGNAL_CLOSESELL 4

extern int    MaxShortTrades   = 1;
extern int    MaxLongTrades    = 1;
int           Order            = SIGNAL_NONE;

// RSI Filter
double RSIfilter=iRSI(Symbol(),0,RSIPeriod,PRICE_CLOSE,BarShift);

// Trade Signal Indicator
double NLD1,NLD2;
      NLD1 = iCustom(NULL,0,"indicator",0,Length,0,0,1,0,0,0,1);
      NLD2 = iCustom(NULL,0,"indicator",0,Length,0,0,1,0,0,0,2);        

// Amount of long / short trades      
int longs  = 0;
int shorts = 0;
double j;
      
      for(j=OrdersTotal()-1;j>=0; j--)
        {
         if(OrderType()==OP_BUY)  longs++;  // Check # of long trades.
         if(OrderType()==OP_SELL) shorts++; // Check # of short trades
        }
                
// place orders
if(longs < MaxLongTrades && NLD1 > NLD2 && RSIfilter>55) Order  = SIGNAL_BUY;        
if(shorts < MaxShortTrades && NLD1 < NLD2 && RSIfilter<45) Order = SIGNAL_SELL;
   

// Signal Begin(Exit Buy)
if (RSIfilter<50) Order=SIGNAL_CLOSEBUY;

if(Order==SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars!=BarCount))))
              {
               dummyResult=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage*PipMultiplier,MediumSeaGreen);
               if(EachTickMode) TickCheck = True;
               if(!EachTickMode) BarCount = Bars;
               return(0);
              }

// Signal Begin(Exit Sell)                                                              
if (RSIfilter>50) Order=SIGNAL_CLOSESELL;

if(Order==SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars!=BarCount))))
                 {
                  dummyResult=OrderClose(OrderTicket(),OrderLots(),Ask,Slippage*PipMultiplier,DarkOrange);
                  if(EachTickMode) TickCheck = True;
                  if(!EachTickMode) BarCount = Bars;
                  return(0);
                 }
 
tfi_markets:

Hi dear coders,

 

I have probably a simple question, but I stuck at the moment on:

My EA is opening and buy and sell orders without problem, but when it comes

to  SIGNAL_CLOSEBUY or SIGNAL_CLOSESELL it doesn't close the orders.

Here I use an RSI_Filter as trigger to close buy or sell orders. 

 I have  copied my code in, I would be very happy if someone could have a look.

Thank you in advance!

 

#define SIGNAL_NONE      0
#define SIGNAL_BUY       1
#define SIGNAL_SELL      2
#define SIGNAL_CLOSEBUY  3
#define SIGNAL_CLOSESELL 4

extern int    MaxShortTrades   = 1;
extern int    MaxLongTrades    = 1;
int           Order            = SIGNAL_NONE;

// RSI Filter
double RSIfilter=iRSI(Symbol(),0,RSIPeriod,PRICE_CLOSE,BarShift);

// Trade Signal Indicator
double NLD1,NLD2;
      NLD1 = iCustom(NULL,0,"indicator",0,Length,0,0,1,0,0,0,1);
      NLD2 = iCustom(NULL,0,"indicator",0,Length,0,0,1,0,0,0,2);        

// Amount of long / short trades      
int longs  = 0;
int shorts = 0;
double j;
      
      for(j=OrdersTotal()-1;j>=0; j--)
        {
         if(OrderType()==OP_BUY)  longs++;  // Check # of long trades.
         if(OrderType()==OP_SELL) shorts++; // Check # of short trades
        }
                
// place orders
if(longs < MaxLongTrades && NLD1 > NLD2 && RSIfilter>55) Order  = SIGNAL_BUY;        
if(shorts < MaxShortTrades && NLD1 < NLD2 && RSIfilter<45) Order = SIGNAL_SELL;
   

// Signal Begin(Exit Buy)
if (RSIfilter<50) Order=SIGNAL_CLOSEBUY;

if(Order==SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars!=BarCount))))
              {
               dummyResult=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage*PipMultiplier,MediumSeaGreen);
               if(EachTickMode) TickCheck = True;
               if(!EachTickMode) BarCount = Bars;
               return(0);
              }

// Signal Begin(Exit Sell)                                                              
if (RSIfilter>50) Order=SIGNAL_CLOSESELL;

if(Order==SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars!=BarCount))))
                 {
                  dummyResult=OrderClose(OrderTicket(),OrderLots(),Ask,Slippage*PipMultiplier,DarkOrange);
                  if(EachTickMode) TickCheck = True;
                  if(!EachTickMode) BarCount = Bars;
                  return(0);
                 }

two issues that you have to solve before proceeding :

  1. You first have to select an order - you never selected the order prior to attempting to close it
  2. You are not checking what is the type of the order that you want to close - check the type and then, according to the order type take further action - and adjust the closing price to bid or ask, dopending on the order type
 
mladen:

two issues that you have to solve before proceeding :

  1. You first have to select an order - you never selected the order prior to attempting to close it
  2. You are not checking what is the type of the order that you want to close - check the type and then, according to the order type take further action - and adjust the closing price to bid or ask, dopending on the order type

Dear Mladen,

thank you very much for your helpful suggestions.

If I understood you correctly I need to implement something like the code below

to select a "buy_ticket" the EA needs to close. The code is not tested yet, and kind of "pseudo state".

 

int buy_ticket=0;
int sell_ticket=0;
int ticket;

// Iterate through tickets
for(int i=OrdersTotal()-1; i>=0; i--)
    {
      if(OrderSelect(i,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 Ticket with trigger
if (RSIfilter<50) Order=SIGNAL_CLOSEBUY;

if (RSIfilter>50) Order=SIGNAL_CLOSESELL; 

                
if(Order==CLOSE_BUY && buy_ticket!=0)
         {
         if(OrderSelect(buy_ticket,SELECT_BY_TICKET))
            {
            if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,clrDodgerBlue))
               Print("Error closing Buy #",(string)OrderTicket()," Error code ",(string)GetLastError());
            }
         }
      else
      if(Order==CLOSE_SELL && sell_ticket!=0)
         {
         if(OrderSelect(sell_ticket,SELECT_BY_TICKET))
            {
            if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,clrDodgerBlue))
               Print("Error closing Sell #",(string)OrderTicket()," Error code ",(string)GetLastError());
            }
         }
    
 
tfi_markets:

Dear Mladen,

thank you very much for your helpful suggestions.

If I understood you correctly I need to implement something like the code below

to select a "buy_ticket" the EA needs to close. The code is not tested yet, and kind of "pseudo state".

 

int buy_ticket=0;
int sell_ticket=0;
int ticket;

// Iterate through tickets
for(int i=OrdersTotal()-1; i>=0; i--)
    {
      if(OrderSelect(i,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 Ticket with trigger
if (RSIfilter<50) Order=SIGNAL_CLOSEBUY;

if (RSIfilter>50) Order=SIGNAL_CLOSESELL; 

                
if(Order==CLOSE_BUY && buy_ticket!=0)
         {
         if(OrderSelect(buy_ticket,SELECT_BY_TICKET))
            {
            if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,clrDodgerBlue))
               Print("Error closing Buy #",(string)OrderTicket()," Error code ",(string)GetLastError());
            }
         }
      else
      if(Order==CLOSE_SELL && sell_ticket!=0)
         {
         if(OrderSelect(sell_ticket,SELECT_BY_TICKET))
            {
            if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,clrDodgerBlue))
               Print("Error closing Sell #",(string)OrderTicket()," Error code ",(string)GetLastError());
            }
         }
    

Do you have only 1 order (same magic,symbol I mean) opened at the same time?

If yes, then it will work.

 

Dear friends,

The attached ea is constantly open orders to fixed lot (it's open all orders 0.10)

I don't change or control open orders lot value!!


Available in settings "Lots" and "MaximumRisk" values, but they are not effective on the orders lot values!

CAn you help me please?

 

hello mr mladen

could you make a empty sub window similar this picture

regard 

 

 

Hi Mladen, I have downloaded your

stepma_pdf_4_4.ex4 as well as the histgram,

copied them into MT4. Draging them onto the chart window

I get the following message, pls see in the image:

Would you tell me how I can use your indicator?


Lea


ps. the same happend with: averages_-_mtf__alerts_7_4.ex4 and histogram

Files:
warning.jpg  20 kb
Reason: