[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 934

 

Problem. Please advise.

In OrderSelect(0,SELECT_BY_POS,MODE_HISTORY)

The OrderProfit() returns the first profit in the history list,

how can I make it return the last profit in the history list?

I tried it this way:

A=OrdersHistoriTotal();

OrderSelect(A,SELECT_BY_POS,MODE_HISTORY);

OrderProfit() returns nothing at all)

)) but it is not working

 

Professionals, please advise how to fix the script. I use a script to export data

int start()
  {
  out_hist("EURUSD",1440);
  out_hist("GBPUSD",1440);
  out_hist("USDJPY",1440);
  out_hist("USDCAD",1440);
  out_hist("AUDUSD",1440);
//

  
  return(0);
  }
//  
int out_hist(string ccy, int tf)
{
  string fname = ccy + tf + ".txt";
  int handle = FileOpen(fname, FILE_CSV|FILE_WRITE, ",");
  if(handle>0)
    {
     FileWrite(handle,"<TICKER>,<DTYYYYMMDD>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>");    // header
     for(int i=iBars(ccy,tf)-1; i>=0; i--)
       {
       string P =ccy + tf;
       string date1 = TimeToStr(iTime(ccy,tf,i),TIME_DATE);
       date1 = StringSubstr(date1,0,4) + StringSubstr(date1,5,2) + StringSubstr(date1,8,2);
       string time1 = TimeToStr(iTime(ccy,tf,i),TIME_MINUTES);
       FileWrite(handle, P, date1, time1, iOpen(ccy,tf,i), iHigh(ccy,tf,i), iLow(ccy,tf,i), iClose(ccy,tf,i), iVolume(ccy,tf,i));
       }
     FileClose(handle);
     }
//----
   return(0);

I get 5 files with data in the output. I want to get 1 file, which will contain data on the first instrument, then the second, etc. I can't get it all into one file... Thanks.

 
kon12:

Professionals, please advise how to fix the script. I use a script to export data

The output is 5 files with data. I want to get 1 file, which will contain data on the first instrument, then the second, etc. I can't get it all into one file... Thanks.


Use file opening to read and write, move to the end of the file and add

FileOpen(fname,FILE_WRITE|FILE_READ);

FileSeek()

help you

 
gheka:

Problem. Please advise.

In OrderSelect(0,SELECT_BY_POS,MODE_HISTORY)

The OrderProfit() returns the first profit in the history list,

how can I make it return the last profit in the history list?

I tried it this way:

A=OrdersHistoriTotal();

OrderSelect(A,SELECT_BY_POS,MODE_HISTORY);

OrderProfit() returns nothing at all)

)) but it is not working


So the last warrant has yet to be found. And which is the last one. By the opening or closing time. And, of course, do not forget which instrument to look for.
 
advise what to write in an EA for a hard limit the maximum volume of the transaction? it just decides which volume to open but sometimes opens a large volume and then go broke, I need to limit the maximum 0.5
 
ilmur:
advise what to write in an EA for a hard limit the maximum volume of the transaction? it just decides which volume to open but sometimes opens a large volume and then go broke, I need to limit the maximum 0.5
extern double MyMaxVolume=0.5;

...

if(рассчитанный_объем > MyMaxVolume) рассчитанный_объем=MyMaxVolume;
 
Necron:

If a person knew, he would have done it himself. But here it looks like you have to make changes to someone else's code
 

Thank you

 
extern double SL=20; // SL для открываемого ордера
extern double TP=20; // ТР для открываемого ордера
extern double Lot=0.01; // Жестко заданное колич. лотов
datetime time;
//--------------------------------------------------------------- 2 --
int start()
{
int Total;

double
M_0,
M_1;


bool
Ans =false, // Ответ сервера после закрытия
Cls_B=false, // Критерий для закрытия Buy
Cls_S=false, // Критерий для закрытия Sell
Opn_B=false, // Критерий для открытия Buy
Opn_S=false; // Критерий для открытия Sell

//--------------------------------------------------------------- 3 --
// Учёт ордеров


for(int i=OrdersTotal()-1;i>=0;i--)
if (OrderSelect(i,SELECT_BY_POS)&&OrderSymbol()==Symbol()&&OrderType()>1)Total++;

if(Total!=0 || time==Time[1])return;


// Торговые критерии

M_0=iOsMA(NULL,0,13,34,8,0,0); // 0 бар
M_1=iOsMA(NULL,0,13,34,8,0,1); // 1 бар



if (M_1<0 && M_0>0)
Opn_B=true;

if (M_1>0 && M_0<0)
Opn_S=true;

//--------------------------------------------------------------- 7 --


if (Opn_B)
{OrderSend(Symbol(),OP_BUY,Lot,Ask,0,Bid-SL*Point,Bid+TP*Point);time=Time[1];}

if (Opn_S)
{OrderSend(Symbol(),OP_SELL,Lot,Bid,0,Ask+SL*Point,Ask-TP*Point);time=Time[1];}
}


An EA that opens a position when the OsMA crosses the zero line. It is not clear where it opens and it is not clear why. See if iOsMA(NULL,0,13,34,8,0,0) has an error?
 
bool isCloseLastPosByStop(string sy="", int op=-1, int mn=-1) {
  datetime t;
  double   ocp, osl;
  int      dg, i, j=-1, k=OrdersHistoryTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderCloseTime()) {
                t=OrderCloseTime();
                j=i;
              }
            }
          }
        }
      }
    }
  }
  if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) {
    dg=MarketInfo(sy, MODE_DIGITS);
    if (dg==0) if (StringFind(OrderSymbol(), "JPY")<0) dg=4; else dg=2;
    ocp=NormalizeDouble(OrderClosePrice(), dg);
    osl=NormalizeDouble(OrderStopLoss(), dg);
    if (ocp==osl) return(True);
  }
  return(False);
}

It's not working, maybe I need to change something here or put it after the start.

I tried to translate your code on paper into Russian I understand, but it doesn't work,

it's too complicated, especially when the conditions in each condition follow, and one condition out of eight conditions.

Of course I don't argue who created this code is a miracle, but for me it's a complete perversion (in a good way)

I am not lazy to add comments to each operation and condition, except for the standard function.

Reason: