Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 89

 
Omm:

how do I determine the time of day trading in futures?

MarketInfo(Symbol(),MODE_STARTING)

MarketInfo(Symbol(),MODE_EXPIRATION)

returns zeros


which broker ?

So first of all, you should check with your broker.

 
alexey1979621:
Dear forum members, how to write the condition of crossing the channel line by the price in your Expert Advisor, for example, the price crosses the channel line from above and the trade is opened or closed? Please note that I am interested in the moment of this crossover. I would be glad to help.

double price0=NormalizeDouble(ObjectGetValueByShift("NameYourChannelLine", 0),Digits)); - value of your line on bar 0.

double price1=NormalizeDouble(ObjectGetValueByShift("NameYourChannelLine", 1),Digits)); - value of your line on bar 1.

And the simplest way to determine the moment of breakdown on the zero bar: if(High[0]>price0 && High[1]<=price1) {the line has broken through upwards}, if(Low[0]<price0 && Low[1]>=price1) {the line has broken through downwards}. The ifs will be TRUE from the moment of the breakthrough until the end of the current bar. It is desirable that your channel line has the property OBJPROP_RAY==True

 
alexey1979621:
Dear forum members, how to make a condition in an EA for crossing the channel line, for example, if the price crosses the channel line from above and a deal is opened or closed? Please note that I am interested in the moment of this crossover. I would be glad to help.

A couple of ways:

If Ask > channel line and Low[1] <=channel line, cross upwards

If Bid < channel line and High[1] >=channel line, cross downwards

You may check with MA with period 1

 
how can I select the last CLOSED order in the software and get information from it?
 
Thank you for your help

. I must have put the question incorrectly, I should have attached part of the code. I stand corrected.

As suggested by

artmedia70 indicated the intersection to close as follows. It closes the deal according to the screenshot. But we need to close the deal where the cross is

void CheckForClose()
{
double PriceHigh, PriceLow;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;

PriceHigh = iCustom (Symbol(), 0, "ExtremeTMALine", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, TrendThreshold, Distances, 1, 0);
PriceLow = iCustom (Symbol(), 0, "ExtremeTMALine", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, TrendThreshold, Distances, 2, 0);


for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=124 || OrderSymbol()!=Symbol()) continue;
//---- check order type
if(OrderType()==OP_BUY)
{
if(Low[1]<=PriceHigh && Ask>=PriceHigh ) OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
break;
}
if(OrderType()==OP_SELL)
{
if(High[1]>=PriceLow && Bid<=PriceLow) OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
break;
}
}
//----
}

 
 
webip:
how can you select the last CLOSED order in the software and get information from it?

You can find anything you like.
 
alexey1979621:
Thank you for your help

. I must have put the question incorrectly, I should have attached part of the code. I stand corrected.

As suggested by

artmedia70 indicated the intersection to close as follows. The deal is closing according to the screenshot. But we need to close the deal where the cross is

void CheckForClose()
{
double PriceHigh, PriceLow;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;

PriceHigh = iCustom (Symbol(), 0, "ExtremeTMALine", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, TrendThreshold, Distances, 1, 0);
PriceLow = iCustom (Symbol(), 0, "ExtremeTMALine", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, TrendThreshold, Distances, 2, 0);


for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=124 || OrderSymbol()!=Symbol()) continue;
//---- check order type
if(OrderType()==OP_BUY)
{
if(Low[1]<=PriceHigh && Ask>=PriceHigh ) OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
break;
}
if(OrderType()==OP_SELL)
{
if(High[1]>=PriceLow && Bid<=PriceLow) OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
break;
}
}
//----
}

ExtremeTMA - ungodly overdrawing. It's a big chunk of history - the last 30 bars, if not more. I used it to write an Expert Advisor - it is rubbish. Imagine: a signal appears, I reached it, but some time later the signal does not exist on the history - the indicator re-drawn and it turns out that I have entered for nothing

You made a mistake when determining the crossing: if(Low[1]<=PriceHigh && Ask>=PriceHigh ) ... you should write if(Low[1]<=PriceHigh && Ask>PriceHigh ) ... And for the opposite by analogy.

Insert the code with button SRC in the panel at the top of input window of your message

ZZZY So where's the screenshot with the cross?

 
artmedia70:

ExtremeTMA - they're ungodly overdrawn. And a huge chunk of history - the last 30 bars, if not more. I used it to write an Expert Advisor - it sucks. Just imagine: I got a signal, entered it, and some time later the signal does not exist on the history - the indicator made too many redraws and it turns out that I entered the market in vain

You made a mistake when determining the crossing: if(Low[1]<=PriceHigh && Ask>=PriceHigh ) ... you should write if(Low[1]<=PriceHigh && Ask>PriceHigh ) ... And for the opposite by analogy.

SZY The code should be pasted by pressing the SRC button in the panel at the top of text entry window


Corrected, closed the trade the same way as in the screenshot above, and should be where the red cross is.

I agree that ExtremeTMA redraws, but I guess it does not affect the search for entry points, the main thing here is the filters. I used TDI indicator. I attached attached what I made (I don't have good hands, that's why the Expert Advisor is a good project ). I have only one problem with it, it takes about 5 hours in tester for 1 year (I have made one mistake somewhere). If it is not difficult to look for errors.

extern double  Lots             = 0.1;
extern string Сomment           = "TMA Canal2";
extern int TakeProfit           = 20;     //тейкпрофит (отрицательное число или ноль чтобы не использовать);
extern int StopLoss             = 20;     // уровень Stop Loss для покупки;
extern int Slippage             = 2; // проскальзывание 
extern int Magic                = 124;

extern string  Indi             = "ExtremeTMALine";
extern string TimeFrame         = "current time frame";
extern int    HalfLength        = 56;
extern int    Price             = PRICE_CLOSE;
extern double ATRMultiplier     = 2.0;
extern int    ATRPeriod         = 100;
extern bool   Interpolate       = true;
extern double TrendThreshold    = 0.5;
extern bool   Distances         = false;


extern string  Indicatora       = "TradersDynamicIndex";
extern int RSI_Period           = 13;         //8-25
extern int RSI_Price            = MODE_CLOSE;           //0-6
extern int Volatility_Band      = 34;    //20-40
extern int RSI_Price_Line       = 2;      
extern int RSI_Price_Type       = MODE_SMA;      //0-3
extern int Trade_Signal_Line    = 7;   
extern int Trade_Signal_Type    = MODE_SMA;   //0-3
extern bool UseAlerts           = false;

double PriceHigh, PriceLow, SL, TP, TDIHigh, TDILow, RSIPriceLine, TradeSignalLine;
int ticket;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
      if (Digits ==3 || Digits ==3) // для пятизначного брокера
         {
            TakeProfit *= 10;
            StopLoss *= 10;
            Slippage *= 10;
         }
      return(0);
}


//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==124)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
//---- return orders volume
   if(buys>0) return(buys);
   else       return(-sells);
  }
   
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double PriceHigh, PriceLow, TDIHigh, TDILow, RSIPriceLine, TradeSignalLine;
   int ticket;

//---- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
   
   PriceHigh = iCustom (Symbol(), 0, "ExtremeTMALine", TimeFrame, HalfLength , Price, ATRMultiplier, ATRPeriod, Interpolate, TrendThreshold, Distances, 1, 0);
   PriceLow = iCustom (Symbol(), 0, "ExtremeTMALine", TimeFrame, HalfLength , Price, ATRMultiplier, ATRPeriod, Interpolate, TrendThreshold, Distances, 2, 0);
   TDIHigh = iCustom (Symbol(), 0, "TradersDynamicIndex", RSI_Period, RSI_Price, Volatility_Band, RSI_Price_Line, RSI_Price_Type, Trade_Signal_Line, Trade_Signal_Type,UseAlerts, 1, 0); // голубая
   TDILow = iCustom (Symbol(), 0, "TradersDynamicIndex", RSI_Period, RSI_Price, Volatility_Band, RSI_Price_Line, RSI_Price_Type, Trade_Signal_Line, Trade_Signal_Type,UseAlerts, 3, 0); // голубая 
   RSIPriceLine = iCustom (Symbol(), 0, "TradersDynamicIndex", RSI_Period, RSI_Price, Volatility_Band, RSI_Price_Line, RSI_Price_Type, Trade_Signal_Line, Trade_Signal_Type,UseAlerts, 4, 0); // зеленая
   TradeSignalLine = iCustom (Symbol(), 0, "TradersDynamicIndex", RSI_Period, RSI_Price, Volatility_Band, RSI_Price_Line, RSI_Price_Type, Trade_Signal_Line, Trade_Signal_Type,UseAlerts, 5, 0); // красная
   
   
   if(Open[1]>PriceHigh || Close[1]>PriceHigh || High[1]>PriceHigh && Ask<=PriceHigh || Ask>=PriceHigh && TDIHigh > 68 && RSIPriceLine < TradeSignalLine)  

     {
      ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"TMA Canal2",124,0,Red);
      return;
     }
//---- buy conditions
   if(Open[1]<PriceLow || Close[1]<PriceLow || Low[1]<PriceLow && Bid>=PriceLow || Bid<=PriceLow && TDILow < 32 && RSIPriceLine > TradeSignalLine)  

     {
      ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"TMA Canal2",124,0,Blue);
      return;
     }
//----
  }

  //+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
   double PriceHigh, PriceLow;
//---- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
 
   PriceHigh = iCustom (Symbol(), 0, "ExtremeTMALine", TimeFrame, HalfLength , Price, ATRMultiplier, ATRPeriod, Interpolate, TrendThreshold, Distances, 1, 0); 
   PriceLow = iCustom (Symbol(), 0, "ExtremeTMALine", TimeFrame, HalfLength , Price, ATRMultiplier, ATRPeriod, Interpolate, TrendThreshold, Distances, 2, 0); 
   
   
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
      if(OrderMagicNumber()!=124 || OrderSymbol()!=Symbol()) continue;
      //---- check order type 
      if(OrderType()==OP_BUY)
        {
         if(Low[1]<=PriceHigh && Ask>PriceHigh) OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(High[1]>=PriceLow && Bid<PriceLow) OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
         break;
        }
     }
//----
  }

//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void start()
   {
//---- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
   if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
   else                                    CheckForClose();
//----
  }
 
alexey1979621:

Corrected, closed the trade the same way as in the screenshot above, but where the red cross should be.

I agree that ExtremeTMA is overdrawing, but I guess it doesn't affect the search for entry points, the main thing here is the filters. I used TDI indicator. I attached attached the tip (my hands are not straightforward, the Expert Advisor project is just like my hands). I have only one problem with it, it takes about 5 hours in tester for 1 year (I have made one mistake somewhere). If it is not difficult to look for errors.

Haven't looked for errors yet - plenty to do.

In order to close Sell where the red cross is, you need to check on the current bar. If Ask<= close level && High[1]>close level

Reason: