[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 441

 

Hi all!

I can't seem to get the deposit load correctly in the trading report. )) I do this:

#define RA 10000

if(Trade_Report == TRUE && !IsOptimization())
   {  int      pos;
      int      handle;
      int      Days;
      double   Swap_M;
      double   Profit_M;
      double   Swap_P;
      double   Profit_P;

      double   Source_LP[RA], LP_01[RA], LP_02[RA], LP_03[RA], LP_04[RA], LP_05[RA], LP_06[RA];
      double   Source_LP_02[RA], LP_01_02[RA], LP_02_02[RA], LP_03_02[RA], LP_04_02[RA], LP_05_02[RA], LP_06_02[RA];
      double   Source_SP[RA], SP_01[RA], SP_02[RA], SP_03[RA], SP_04[RA], SP_05[RA], SP_06[RA];
      double   Source_SP_02[RA], SP_01_02[RA], SP_02_02[RA], SP_03_02[RA], SP_04_02[RA], SP_05_02[RA], SP_06_02[RA];
      double   Load_Depo[RA]; 
   
      handle = FileOpen("OrdersReport.csv",FILE_CSV|FILE_WRITE);
   
      if(handle > 0)
                {//1
            FileWrite(handle,"Time Close"+","+"Lots"+","
                              +"Swap($)"+","+"Profit($)"+","+"Swap(p)"+","+"Profit(p)"+","+"Load Depo"+","
                              +"SOURCE_LP"+","+"LP#01"+","+"LP#02"+","+"LP#03"+","+"LP#04"+","+"LP#05"+","+"LP#06"+","
                              +"SOURCE_SP"+","+"SP#01"+","+"SP#02"+","+"SP#03"+","+"SP#04"+","+"SP#05"+","+"SP#06");
            for(pos = 0; pos < OrdersHistoryTotal(); pos++)
               {  OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY); //2
               
                  if(OrderType() == OP_BUY && OrderMagicNumber() == Magic_Source_LP && OrderCloseTime() == TimeCurrent()) { Source_LP[pos] = OrderProfit(); }
                  if(OrderType() == OP_BUY && OrderMagicNumber() == Magic_LP01 && OrderCloseTime() == TimeCurrent()) { LP_01[pos] = OrderProfit(); }
                  if(OrderType() == OP_BUY && OrderMagicNumber() == Magic_LP02 && OrderCloseTime() == TimeCurrent()) { LP_02[pos] = OrderProfit(); }
                  if(OrderType() == OP_BUY && OrderMagicNumber() == Magic_LP03 && OrderCloseTime() == TimeCurrent()) { LP_03[pos] = OrderProfit(); }
                  if(OrderType() == OP_BUY && OrderMagicNumber() == Magic_LP04 && OrderCloseTime() == TimeCurrent()) { LP_04[pos] = OrderProfit(); }
                  if(OrderType() == OP_BUY && OrderMagicNumber() == Magic_LP05 && OrderCloseTime() == TimeCurrent()) { LP_05[pos] = OrderProfit(); }
                  if(OrderType() == OP_BUY && OrderMagicNumber() == Magic_LP06 && OrderCloseTime() == TimeCurrent()) { LP_06[pos] = OrderProfit(); }
                     
                  if(OrderType() == OP_SELL && OrderMagicNumber() == Magic_Source_SP && OrderCloseTime() == TimeCurrent()) { Source_SP[pos] = OrderProfit(); }
                  if(OrderType() == OP_SELL && OrderMagicNumber() == Magic_SP01 && OrderCloseTime() == TimeCurrent()) { SP_01[pos] = OrderProfit(); }
                  if(OrderType() == OP_SELL && OrderMagicNumber() == Magic_SP02 && OrderCloseTime() == TimeCurrent()) { SP_02[pos] = OrderProfit(); }
                  if(OrderType() == OP_SELL && OrderMagicNumber() == Magic_SP03 && OrderCloseTime() == TimeCurrent()) { SP_03[pos] = OrderProfit(); }
                  if(OrderType() == OP_SELL && OrderMagicNumber() == Magic_SP04 && OrderCloseTime() == TimeCurrent()) { SP_04[pos] = OrderProfit(); }
                  if(OrderType() == OP_SELL && OrderMagicNumber() == Magic_SP05 && OrderCloseTime() == TimeCurrent()) { SP_05[pos] = OrderProfit(); }
                  if(OrderType() == OP_SELL && OrderMagicNumber() == Magic_SP06 && OrderCloseTime() == TimeCurrent()) { SP_06[pos] = OrderProfit(); }
                  
            //--- Вычисление загрузки депозита ---//
                  int              Amount_LD;
                  datetime         CurrentCloseTime = OrderCloseTime();
                  static datetime  CloseTime;                  
                  
                  if(CurrentCloseTime != CloseTime)
                     { Amount_LD = 1;
                       Load_Depo[pos] = (Amount_LD*(OrderLots()*1000)/AccountBalance())*100;
                       CloseTime = OrderCloseTime(); }
                  else if(CurrentCloseTime == CloseTime)
                          { Amount_LD++;
                            Load_Depo[pos] = (Amount_LD*(OrderLots()*1000)/AccountBalance())*100;
                            CloseTime = OrderCloseTime(); }
            //---------------------------------------------------------------------------------------------------------------------
                     
                  Swap_M     =  OrderSwap();
                  Profit_M   =  OrderProfit();
                  Swap_P     = (OrderSwap()/10)/OrderLots();
                  Profit_P   = (OrderProfit()/10)/OrderLots()+(OrderSwap()/10)/OrderLots();
                     
                  if(OrderType() == OP_BUY || OrderType() == OP_SELL)
                     {   FileWrite(handle,TimeToStr(OrderCloseTime(),TIME_DATE|TIME_MINUTES)+","+DoubleToStr(OrderLots(),2)+"," //3
                                          
                                          +DoubleToStr(OrderSwap(),2)+","+DoubleToStr(Profit_M+Swap_M,2)+","+DoubleToStr(Swap_P,2)+","
                                          +DoubleToStr(Profit_P,2)+","+DoubleToStr(Load_Depo[pos],2)+","
                                          
                                          +DoubleToStr(Source_LP[pos],2)+","+DoubleToStr(LP_01[pos],2)+","+DoubleToStr(LP_02[pos],2)+","
                                          +DoubleToStr(LP_03[pos],2)+","
                                          +DoubleToStr(LP_04[pos],2)+","+DoubleToStr(LP_05[pos],2)+","+DoubleToStr(LP_06[pos],2)+","
                                             
                                          +DoubleToStr(Source_SP[pos],2)+","+DoubleToStr(SP_01[pos],2)+","+DoubleToStr(SP_02[pos],2)+","
                                          +DoubleToStr(SP_03[pos],2)+","
                                          +DoubleToStr(SP_04[pos],2)+","+DoubleToStr(SP_05[pos],2)+","+DoubleToStr(SP_06[pos],2));  } //3
               }  FileClose(handle); //2
         }//1

As a result, it is not calculated correctly initially. Values in array Load_Depo constantly change and need, that open positions too were considered. Show me an example, someone, if you have a spare minute. ))

 
demlin:
Honestly, I don't get it, it's so complicated)))
Not even the examples from the test script help?
 
FreeSerfer:

Thanks, the point is clear, I'm sorry that I'm not very good with the programming language.

Suppose:

Blue - number 0 - buy signal

Red - number 1 - sell signal

and another question, the arrow can flash while it is forming a bar above which it can lock and give a signal. The deals should be opened after the signal is formed

Can someone implement this in code?

Are you studying the programming or looking for someone to do it for you?

Victor has already explained that the iCustom() function should be used. Read about it in MetaEditor's help. It is quite detailed there. To avoid a "flutter" - use in iCustom() the data of the first bar instead of zero - it has already been completely formed.

When you start to write something yourself, you'll be glad to get help and correction here...

 
artmedia70:

Are you learning to program or are you looking for someone to do it for you?

Victor has already made it clear to you that you need to use the iCustom() function. Read about it in MetaEditor's help. It is quite detailed there. To get rid of "chatter" - use the data of the first bar instead of zero bar in iCustom() - it has already been completely formed.

When you start to write at least something yourself, then they will help you here with pleasure and will correct anything...

I write myself, although it's hard for me, and the only thing left is the binding of the Expert Advisor to the indicator, although thanks to Victor it will soon be solved with my own efforts. In any case, thanks to all who responded and showed me the direction in which to move forward.
 
peshihod:

There can be countless options. It is best to choose the simple ones. For example:


int Orderov;
int Tip;

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int i,k;

Orderov=OrdersTotal();

for(i=0;i<Orderov;i++)
{
OrderSelect(i,SELECT_BY_POS);

switch( OrderType() )
{
case OP_BUY:
//Задача для ордера типа OP_BUY
break;

case OP_SELL:
//Задача для ордера типа OP_BUY
break;

case OP_BUYLIMIT:
//Задача для ордера типа OP_BUY
break;

/////------ и т.д.




}
}

return(0);
}

Help.... Answer the question ..............

This is the part which is triggered on every tick

case OP_BUY:
//Задача для ордера типа OP_BUY
break;

case OP_SELL:
//Задача для ордера типа OP_BUY
break;


And it should only be triggered with every new order opened, once.

Maybe you need to add some counter, by ticks, magiks or other orders identifier?

----------------------------------------------------------------------------------------

Do we have to create a variable Orderov ?
Can I do it this way?

for(i=0;i<OrdersTotal();i++)

Do you need a variable "k" in the script ?

int i,k;

 
Zhunko:
That even the examples from the test script don't help?
Thanks for the feedback, got around the problem in a different, simpler way ))
 
semiromid:

This is the part that is triggered on every tick

case OP_BUY:
//Задача для ордера типа OP_BUY
break;

case OP_SELL:
//Задача для ордера типа OP_BUY
break;


And it should be triggered only once with each new order opened.

Maybe there should be a counter attached, by ticks, magiks or other order identifier?

----------------------------------------------------------------------------------------

Do we have to make a variable Orderov ?
Can we do it this way ?

for(i=0;i<OrdersTotal();i++)

The script needs a variable "k" ?

You got it all wrong.

You're trying to compose poetry in German without knowing a word. Do I make myself clear?

Read the reference, learn all the functions and properties of the language. It'll take you a couple of months. Use the examples that are included in the installation of MetaTrader4. Then we will talk. You don't know what we're talking about yet.

 
peshihod:

You've got it all wrong.

Trying to compose poetry in German without knowing a single word. Do I make myself clear?

Read the reference, learn all the functions and properties of the language. It'll take you a couple of months. Use the examples that are included in the installation of MetaTrader4. Then we will talk. You don't know what we are talking about yet.


I am a beginner in programming, and I have no teachers. And if it is difficult for you to answer the questions that are important to me, you could have written nothing to me.

And I'm addressing you as you, actually.....

 
semiromid:


I am a beginner in programming, and I have no teachers. If it is difficult for you to answer the questions that are important to me, you could have written nothing to me.

And I'm addressing you as you, actually.....


I'm sorry.

I wrote about how you can't learn to swim ashore.

 
peshihod:


Excuse me.

I wrote about how you can't learn to swim ashore.


Sometimes you have to ask questions to understand something .

int Orderov;
int Tip;

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int i,k;

Orderov=OrdersTotal();

for(i=0;i<Orderov;i++)
{
OrderSelect(i,SELECT_BY_POS);

switch( OrderType() )
{
case OP_BUY:
//Задача для ордера типа OP_BUY
break;

case OP_SELL:
//Задача для ордера типа OP_BUY
break;

case OP_BUYLIMIT:
//Задача для ордера типа OP_BUY
break;

/////------ и т.д.




}
}

return(0);
}

Help.... Answer the question ..............

This is the part that triggers every tick.

case OP_BUY:
//Задача для ордера типа OP_BUY
break;

case OP_SELL:
//Задача для ордера типа OP_BUY
break;


It should only be triggered every time a new order is open, once.

Maybe I need to attach some counters, by ticks, magiks or other orders identifiers, or maybe arrays? I dont know what it has to do with it, I can't move forward until I figure it out.

----------------------------------------------------------------------------------------

Do we have to make a variable Orderov ?
Can I do it this way?

for(i=0;i<OrdersTotal();i++)

Does the script need a variable "k" ?

int i,k;

Reason: