Skip to content

code #4

@mosiwarrior

Description

@mosiwarrior

//+------------------------------------------------------------------+
//| Fisher_Final_Corrected.mq5 |
//+------------------------------------------------------------------+
#include <Trade\Trade.mqh>
CTrade trade;

double PointA = 0;
double PointC = 0;
bool RangeSet = false;

void OnTick()
{
// ۱. لودِ سطوح
if(!RangeSet)
{
datetime today = TimeCurrent();
MqlDateTime dt;
TimeToStruct(today, dt);
dt.hour = 0; dt.min = 0; dt.sec = 0;

  int barIndex = iBarShift(_Symbol, PERIOD_H1, StructToTime(dt));
  if(barIndex >= 0)
  {
     PointA = iHigh(_Symbol, PERIOD_H1, barIndex);
     PointC = iLow(_Symbol, PERIOD_H1, barIndex);
     if(PointA > 0) RangeSet = true;
  }
  return; 

}

// ۲. خواندن حجم با روش ۳ پارامتری (تضمینی برای رفع خطا)
long vol = 0;
// متغیر vol باید حتماً در پارامتر سوم باشد تا کامپایلر خطا نگیرد
bool res = SymbolInfoInteger(_Symbol, SYMBOL_VOLUME_REAL, vol);

static long lastVol = 0;
bool isHighVolume = (res && lastVol > 0 && vol > lastVol * 1.2);
lastVol = vol;

// ۳. منطقِ ورود
if(PositionsTotal() == 0)
{
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
double dist = 15.0;

  if(bid <= PointC + 5.0 && bid >= PointC - 0.5) {
     trade.Buy(0.01, _Symbol, ask, ask - dist, ask + dist);
  }
  else if(ask >= PointA - 5.0 && ask <= PointA + 0.5) {
     trade.Sell(0.01, _Symbol, bid, bid + dist, bid - dist);
  }
  else if(isHighVolume)
  {
     if(ask > PointA + 2.0) trade.Buy(0.01, _Symbol, ask, ask - dist, ask + dist);
     else if(bid < PointC - 2.0) trade.Sell(0.01, _Symbol, bid, bid + dist, bid - dist);
  }

}

// ۴. مدیریت سود
for(int i=PositionsTotal()-1; i>=0; i--)
{
ulong ticket = PositionGetTicket(i);
if(PositionSelectByTicket(ticket))
{
double profit = PositionGetDouble(POSITION_PROFIT);
double sl = PositionGetDouble(POSITION_SL);
double openPrice = PositionGetDouble(POSITION_PRICE_OPEN);

     if(profit >= 8.0 && MathAbs(sl - openPrice) > 0.001)
     {
        trade.PositionModify(ticket, openPrice, PositionGetDouble(POSITION_TP));
     }
  }

}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions