Code not working (struct member undefined)

 

Hi guys,

i am facing error 'Struct member undefined' on the following line of code

    if(Pos.PriceCurrent>=(NormalizeDouble(i*Target_Increment+NormalizeDouble(First_Stop+Pos.PriceOpen,_Digits),_Digits)))


I have included the following at the heading

#include <Trade/Trade.mqh>
#include <Trade/SymbolInfo.mqh>
#include <Trade/DealInfo.mqh>
#include <Trade/PositionInfo.mqh>

CTrade Trade;
CDealInfo Deal;
CSymbolInfo Sym;

CPositionInfo Pos;

Where am i going wrong? P/S i am new at coding.

regards
 

 if(Pos.PriceCurrent>=(NormalizeDouble(i*Target_Increment+NormalizeDouble(First_Stop+Pos.PriceOpen,_Digits),_Digits)))

Dot  "."  symbol is not allowed in variable names since Metatrader v600. 

Solution is to remove the dot or replace it with some allowed symbol (for example underscore: Pos_PriceCurrent). 

 
drazen64:


Dot  "."  symbol is not allowed in variable names since Metatrader v600. 


Whilst the period is not allowed in variables, Dot notation is used to address members of Classes/Structures which it appears stahm007 is attempting to do here (hence the struct definition error)

Stahm, are you coding this in MT5? Can you show more of your code please?
 
Filter:
Whilst the period is not allowed in variables, Dot notation is used to address members of Classes/Structures which it appears stahm007 is attempting to do here (hence the struct definition error)

Stahm, are you coding this in MT5? Can you show more of your code please?
Hi Mr Moderator and Drazen,

I am coding in MT5, as i said earlier i am still learning and attached in the EA. I am trying to work on the piece of code for scaling out of a position and have only input for the buy condition (am also testing if i have placed in the write position to execute it).

When i have resolved this i would like to add ASI indicator to the code, been searching where its been used before to see how to define and use it in code.

#property copyright "NA"
#property link      "soon"
#property version   "1.01"
//--- input parameters
//input int      StopLoss=50;      // Stop Loss
//input int      TakeProfit=20;   // Take Profit
input int      ADX_Period=8;     // ADX Period
input int      MA_Period=20;      // Moving Average Period
input int      EA_Magic=123789;   // EA Magic Number
input double   Adx_Min=25.0;     // Minimum ADX Value
input double   Lot=0.1;          // Lots to Trade
input int      InpRSISperiod=14;  // RSI(14) period
//input double   InpT=300.0;       //ASI T(max price changing
input int      InpRSIFperiod=4;    //RSI(4) period
input int      K_Period = 5;     //K Period (Main line) of Stoch Indicator
input int      D_Period = 3;     //D Period (Signal Line)of Stoch Indicator
input int      Slowing = 3;      // Slowing of Stoch Indicator

//--- Other parameters
int adxHandle; // handle for our ADX indicator
int maHandle;  // handle for our Moving Average indicator
int RSIS_Handle; //handle for theRSI(14) indicator
int RSIF_Handle;// handle for the RSI4 indicator
int KDHandle; // handle for the Stochastic indicator
//int Ind_Handle; //handle for ASI indicator

double plsDI[],minDI[],adxVal[]; // Dynamic arrays to hold the values of +DI, -DI and ADX values for each bars
double maVal[]; // Dynamic array to hold the values of Moving Average for each bars
double RSIS[];  //Array for the RSI(14) indicator
double RSIF[];   // array for the RSI(4) indicator
double K[],D[]; //array for the Stoch indicator
double p_close; // Variable to store the close value of a bar
//double IndBuffer[];//Array for ASI indicator
int STP, TKP;   // To be used for Stop Loss & Take Profit values

//for new TP and SL tracking
#include <Trade/Trade.mqh>
#include <Trade/SymbolInfo.mqh>
#include <Trade/DealInfo.mqh>
#include <Trade/PositionInfo.mqh>

CTrade Trade;
CDealInfo Deal;
CSymbolInfo Sym;
CPositionInfo Pos;

#define OP_BUY 0           //Buy 
#define OP_SELL 1          //Sell
#define MODE_TRADES 0
#define SELECT_BY_POS 0
#define SELECT_BY_TICKET 1
#define MODE_SPREAD 13

//=============== VARS external
input int First_Target = 20;
input int Target_Increment = 5;
input double   Initial_Close_Lot = 0.4;
input double Close_Lots = 0.1;
input bool Move_Stops = true;
input int First_Stop_Target = 0;
input int First_Stop = 0;
input int Second_Stop_Target = 20;
input int Second_Stop = 10;
input bool Use_Max_Loss = true;
input int Max_Loss = 50;
input int iterations =10;
input int Max_TakeProfit = 50;

//=============== VARS internal
int nextTP;
bool sl;
int range = 5;
int multiplier;
// OrderType == 1 is OP_SELL


double MarketInfoMQL4(string symbol,
                      int type)
  {
   switch(type)
     {

      case MODE_SPREAD:
         return(SymbolInfoInteger(_Symbol,SYMBOL_SPREAD));


      default: return(0);
     }
   return(0);
  }


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Get handle for ADX indicator
   adxHandle=iADX(NULL,0,ADX_Period);
//--- Get the handle for Moving Average indicator
   maHandle=iMA(_Symbol,_Period,MA_Period,0,MODE_EMA,PRICE_CLOSE);
//--- Get the handle for the RSI indicator
   RSIS_Handle=iRSI(NULL,0,InpRSISperiod,PRICE_CLOSE);
   RSIF_Handle=iRSI(NULL,0,InpRSIFperiod,PRICE_CLOSE);
//--- Get the handle for the Stoch indicator
   KDHandle=iStochastic(NULL,0,K_Period,D_Period,Slowing,MODE_SMA,STO_CLOSECLOSE); 
//---Get the handle for ASI indicator
//   Ind_Handle=iATR(_Symbol,_Period,PRICE_CLOSE);// looking at ASI indicator
//--- What if handle returns Invalid Handle
   if(adxHandle<0 || maHandle<0 || RSIS_Handle<0 || RSIF_Handle<0 || KDHandle<0) //||Ind_Handle<0)
     {
      Alert("Error Creating Handles for indicators - error: ",GetLastError(),"!!");
      return(-1);
     }

//--- Let us handle currency pairs with 5 or 3 digit prices instead of 4
   STP = Max_Loss;
   TKP = Max_TakeProfit;
   if(_Digits==5 || _Digits==3)
     {
      STP = STP*10;
      TKP = TKP*10;
     }
   return(0);
   
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- Release our indicator handles
   IndicatorRelease(adxHandle);
   IndicatorRelease(maHandle);
   IndicatorRelease(RSIS_Handle);
   IndicatorRelease(RSIF_Handle);
   IndicatorRelease(KDHandle);
   //IndicatorRelease(Ind_Handle);
   
 
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- Do we have enough bars to work with
   if(Bars(_Symbol,_Period)<60) // if total bars is less than 60 bars
     {
      Alert("We have less than 60 bars, EA will now exit!!");
      return;
     }  

// We will use the static Old_Time variable to serve the bar time.
// At each OnTick execution we will check the current bar time with the saved one.
// If the bar time isn't equal to the saved time, it indicates that we have a new tick.

   static datetime Old_Time;
   datetime New_Time[1];
   bool IsNewBar=false;

// copying the last bar time to the element New_Time[0]
   int copied=CopyTime(_Symbol,_Period,0,1,New_Time);
   if(copied>0) // ok, the data has been copied successfully
     {
      if(Old_Time!=New_Time[0]) // if old time isn't equal to new bar time
        {
         IsNewBar=true;   // if it isn't a first call, the new bar has appeared
         if(MQL5InfoInteger(MQL5_DEBUGGING)) Print("We have new bar here ",New_Time[0]," old time was ",Old_Time);
         Old_Time=New_Time[0];            // saving bar time
        }
     }
   else
     {
      Alert("Error in copying historical times data, error =",GetLastError());
      ResetLastError();
      return;
     }

//--- EA should only check for new trade if we have a new bar
   if(IsNewBar==false)
     {
      return;
     }
 
//--- Do we have enough bars to work with
   int Mybars=Bars(_Symbol,_Period);
   if(Mybars<60) // if total bars is less than 60 bars
     {
      Alert("We have less than 60 bars, EA will now exit!!");
      return;
     }

//--- Define some MQL5 Structures we will use for our trade
   MqlTick latest_price;      // To be used for getting recent/latest price quotes
   MqlTradeRequest mrequest;  // To be used for sending our trade requests
   MqlTradeResult mresult;    // To be used to get our trade results
   MqlRates mrate[];          // To be used to store the prices, volumes and spread of each bar
   ZeroMemory(mrequest);      // Initialization of mrequest structure
/*
     Let's make sure our arrays values for the Rates, ADX Values and MA values 
     is store serially similar to the timeseries array
*/
// the rates arrays
   ArraySetAsSeries(mrate,true);
// the ADX DI+values array
   ArraySetAsSeries(plsDI,true);
// the ADX DI-values array
   ArraySetAsSeries(minDI,true);
// the ADX values arrays
   ArraySetAsSeries(adxVal,true);
// the MA-28 values arrays
   ArraySetAsSeries(maVal,true);
// the RSI(4) values arrays
   ArraySetAsSeries(RSIF,true);
// the RSI(14) value array  
   ArraySetAsSeries(RSIS,true);
// the %K, %D, Slowing value array
   ArraySetAsSeries(K,true);
   ArraySetAsSeries(D,true);
   //ArraySetAsSeries(S,true);
// the ASI value array
//   ArraySetAsSeries(IndBuffer,true);

//--- Get the last price quote using the MQL5 MqlTick Structure
   if(!SymbolInfoTick(_Symbol,latest_price))
     {
      Alert("Error getting the latest price quote - error:",GetLastError(),"!!");
      return;
     }

//--- Get the details of the latest 3 bars
   if(CopyRates(_Symbol,_Period,0,5,mrate)<0)
     {
      Alert("Error copying rates/history data - error:",GetLastError(),"!!");
      ResetLastError();
      return;
     }

//--- Copy the new values of our indicators to buffers (arrays) using the handle
   if(CopyBuffer(adxHandle,0,0,5,adxVal)<0 || CopyBuffer(adxHandle,1,0,5,plsDI)<0
      || CopyBuffer(adxHandle,2,0,5,minDI)<0)
     {
      Alert("Error copying ADX indicator Buffers - error:",GetLastError(),"!!");
      ResetLastError();
      return;
     }
   if(CopyBuffer(maHandle,0,0,5,maVal)<0)
     {
      Alert("Error copying Moving Average indicator buffer - error:",GetLastError());
      ResetLastError();
      return;
     }
   if(CopyBuffer(RSIS_Handle,0,0,5,RSIS)<0)
      {
      Alert("Error copying RSI(14) indicator Buffers - error:",GetLastError());
      ResetLastError();
      return;
      }
   if (CopyBuffer(RSIF_Handle,0,0,5,RSIF)<0)
      {
      Alert("Error copying RSI(4)indiactor buffers - error:",GetLastError());
      ResetLastError();
      return;
      }
   if(CopyBuffer(KDHandle,0,0,5,K)<0||CopyBuffer(KDHandle,1,0,5,D)<0)
      {
      Alert("Error copying Stoch indicator buffer - error:",GetLastError());
      ResetLastError();
      return;
      }
/*   if(CopyBuffer(Ind_Handle,0,0,5,IndBuffer)<0) // having problem with this indicator, i want ASI
      {
      Alert("Error copying ASI indicator buffer - error:",GetLastError());
      ResetLastError();
      return;
      }
*/     

//--- Do we have positions opened already?
   bool Buy_opened=false;  // variable to hold the result of Buy opened position
   bool Sell_opened=false; // variables to hold the result of Sell opened position

   if(PositionSelect(_Symbol)==true) // we have an opened position
     {
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
        {
         Buy_opened=true;  //It is a Buy
        }
      else if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
        {
         Sell_opened=true; // It is a Sell
        }
     }

// Copy the bar close price for the previous bar prior to the current bar, that is Bar 1
   p_close=mrate[1].close;  // bar 1 close price

/*
    1. Check for a long/Buy Setup : RSI4 increasing upwards, 
    previous price close above it, ADX > 25, ADX > +DI
*/
   
  
   
//--- Declare bool type variables to hold our Buy Conditions
   bool Buy_Condition_1 = (mrate[3].open<maVal[3]) && (mrate[3].close>maVal[3])&& (mrate[2].close>maVal[2]) && (mrate[1].close>maVal[1]); // bar 4 crosses MA
   bool Buy_Condition_2 = (K[1]>D[1]) && (D[1]<80)&& (K[3]>D[1]); // Stochs pointing up
   bool Buy_Condition_3 = (adxVal[1]>plsDI[1])&&(adxVal[1]>Adx_Min)&&(adxVal[2]>Adx_Min) &&(adxVal[3]>Adx_Min) && (plsDI[1]>Adx_Min); //ADX line above green line and both above min level
   bool Buy_Condition_4 = (RSIS[1]>RSIS[2]); //RSI(14) increasing 
   bool Buy_Condition_5 = (minDI[3]>minDI[2])&&(minDI[2]>minDI[1]); //red ADX line decreases
   bool Buy_Condition_6 = (RSIF[2]<RSIF[1]); // RSI pointing up in direction of trade
   bool Buy_Condition_7 = (maVal[1]>maVal[2])&&(maVal[2]>maVal[3]); //MA Level increasing


//--- Putting all together   
   
   if(Buy_Condition_1)
     {
      if(Buy_Condition_2 && Buy_Condition_3 && Buy_Condition_4)
         {
          if(Buy_Condition_5 && Buy_Condition_6 && Buy_Condition_7)
            {
               // any opened position?
               if(Buy_opened || Sell_opened)
                 {
                  Alert("We already have an open Position!!!");
                  return;    // Don't open a new Buy Position
                 }
               ZeroMemory(mrequest);
               //ZeroMemory(mresult);
               mrequest.action = TRADE_ACTION_DEAL;                                  // immediate order execution
               mrequest.price = NormalizeDouble(latest_price.ask,_Digits);           // latest ask price
               mrequest.sl = NormalizeDouble(latest_price.ask - STP*_Point,_Digits); // Stop Loss
               mrequest.tp = NormalizeDouble(latest_price.ask + TKP*_Point,_Digits); // Take Profit
               mrequest.symbol = _Symbol;                                            // currency pair
               mrequest.volume = Lot;                                                 // number of lots to trade
               mrequest.magic = EA_Magic;                                             // Order Magic Number
               mrequest.type = ORDER_TYPE_BUY;                                        // Buy Order
               mrequest.type_filling = ORDER_FILLING_IOC;                             // Order execution type
               mrequest.deviation=100;                                                // Deviation from current price
               //--- send order
               OrderSend(mrequest,mresult);
               // get the result code
               if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed
                 {
                  Alert("A Buy order has been successfully placed with Ticket#:",mresult.order,"!!");
                 }
               else
                 {
                  Alert("The Buy order request could not be completed -error:",GetLastError());
                  ResetLastError();           
                  return;
                  }
                 
               if(latest_price.bid>=(NormalizeDouble(First_Stop+Pos.PriceOpen,_Digits)))
               {
                  Trade.PositionClose(_Symbol,Initial_Close_Lot*Lot,100);
                  if (Pos.PriceCurrent<NormalizeDouble(latest_price.ask + TKP*_Point,_Digits))
                  {
                     for(int i=1; i<iterations;i++)
                     {
                        if(Pos.PriceCurrent>=(NormalizeDouble(i*Target_Increment+NormalizeDouble(First_Stop+Pos.PriceOpen,_Digits),_Digits)))
                        {
                           Trade.PositionClose(_Symbol,Close_Lots*(Lot-Initial_Close_Lot),100);
                        }
                     }
                  }
               } 
               
            }
         }
    }

thank you for you responses

 

Hi Stahm

I haven't had time to check it but try this out. You also still need to do some work on it as there are warnings showing up from your previous code, only 2 minor ones that you can easily fix. 

Cheers
Stu 

Files:
stahm007.mq5  15 kb
 
Or if you still want to work with the position class, try this version. You had a mix of OOP and procedural and were missing trailing braces when calling the Pos members eg Pos.PriceCurrent should be Pos.PriceCurrent()
Files:
 

Many thanks Stu,


i qill keep you updated on my progress.

 
stahm007:

Many thanks Stu,


i qill keep you updated on my progress.

Very welcome mate :)
 
Filter:
Or if you still want to work with the position class, try this version. You had a mix of OOP and procedural and were missing trailing braces when calling the Pos members eg Pos.PriceCurrent should be Pos.PriceCurrent()

Hi Stu,

many thanks once more, i have tried moving the script but i can seem to get it executed, I want to scale out of a position ay various points and i had hoped the code for doing that.


Regards


Stephen

 
stahm007:

Hi Stu,

many thanks once more, i have tried moving the script but i can seem to get it executed, I want to scale out of a position ay various points and i had hoped the code for doing that.


Regards


Stephen

No worries Stephen. I'm a bit flat out today but will try to take a look at it later this arvo for you mate.

Stu
 

Hi Stu, How have been mate? have you had a moment to assist in the placement of the script so that it executes. I havent had any luck. many thanks. As i said i want to scale out of the position.


Regards


Steve

Filter:
No worries Stephen. I'm a bit flat out today but will try to take a look at it later this arvo for you mate.

Stu