IntraScalper
- Indicatori
- Mangesh Popat Ubale
- Versione: 1.2
- Aggiornato: 13 gennaio 2026
- Attivazioni: 20
EA DOCUMENTATION
#property copyright "ISP Trading System"
#property link ""
#property version "1.00"
#property strict
#include <Trade/Trade.mqh>
#include <Trade/SymbolInfo.mqh>
#include <Trade/PositionInfo.mqh>
input double InpLotSize = 0.1;
input int InpStopLoss = 200;
input int InpTakeProfit = 400;
input ulong InpMagicNumber = 2024;
input bool InpCloseOnOpposite = true;
input string InpSignalPrefix = "ISP_";
input int InpMaxSlippage = 3;
//--- Global Variables
CTrade m_trade; // MQL5 trade class object
CSymbolInfo m_symbol; // Symbol information
CPositionInfo m_position; // Position information
datetime lastSignalTime = 0;
int lastSignalType = -1;
bool isTradeAllowed = true;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit(){
m_symbol.Name(_Symbol);
if(!m_symbol.RefreshRates())
{
Print("Failed to initialize symbol");
return INIT_FAILED;
}
m_trade.SetExpertMagicNumber(InpMagicNumber);
m_trade.SetDeviationInPoints(InpMaxSlippage);
m_trade.SetTypeFilling(ORDER_FILLING_FOK);
if(GlobalVariableCheck(InpSignalPrefix + "SIGNAL_ACTIVE"))
{
Print("ISP Indicator detected");
}
else
{
Print("Warning: No indicator detected or no active signals");
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Print("ISP EA Shutdown");
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
CheckForNewSignals();
}
//+------------------------------------------------------------------+
//| Indicator ke new signals check karo |
//+------------------------------------------------------------------+
void CheckForNewSignals()
{
if(!GlobalVariableCheck(InpSignalPrefix + "SIGNAL_ACTIVE"))
return;
double signalActive = GlobalVariableGet(InpSignalPrefix + "SIGNAL_ACTIVE");
if(signalActive != 1.0)
return;
int signalType = (int)GlobalVariableGet(InpSignalPrefix + "SIGNAL_TYPE");
double signalPrice = GlobalVariableGet(InpSignalPrefix + "SIGNAL_PRICE");
datetime signalTime = (datetime)GlobalVariableGet(InpSignalPrefix + "SIGNAL_TIME");
if(signalTime <= lastSignalTime)
return;
lastSignalTime = signalTime;
lastSignalType = signalType;
Print("New Signal Detected: ", (signalType == 0 ? "BUY" : "SELL"),
" at Price: ", signalPrice,
" Time: ", TimeToString(signalTime));
ExecuteTrade(signalType, signalPrice);
// Signal ko deactivate kardo (tak dobara na chale)
GlobalVariableSet(InpSignalPrefix + "SIGNAL_ACTIVE", 0.0);
}
//+------------------------------------------------------------------+
//| Signal ke basis par trade execute karo |
//+------------------------------------------------------------------+
void ExecuteTrade(int signalType, double signalPrice)
{
m_symbol.RefreshRates();
bool positionExists = false;
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
if(PositionGetSymbol(i) == _Symbol && PositionGetInteger(POSITION_MAGIC) == InpMagicNumber)
{
positionExists = true;
break;
}
}
if(positionExists && InpCloseOnOpposite)
{
CloseAllPositions();
Print("Closed existing position due to new signal");
}
else if(positionExists)
{
Print("Position already exists. Not opening new position.");
return;
}
double slPrice = 0.0, tpPrice = 0.0;
double point = m_symbol.Point();
if(InpStopLoss > 0)
{
slPrice = signalPrice + (signalType == 0 ? -1 : 1) * (InpStopLoss * point);
}
if(InpTakeProfit > 0)
{
tpPrice = signalPrice + (signalType == 0 ? 1 : -1) * (InpTakeProfit * point);
}
if(signalType == 0) // BUY signal
{
double ask = m_symbol.Ask();
if(!m_trade.Buy(InpLotSize, _Symbol, ask, slPrice, tpPrice, "ISP EA BUY Signal"))
{
Print("Buy trade failed: ", m_trade.ResultRetcodeDescription());
}
else
{
Print("Buy trade executed at ", ask, " Lot: ", InpLotSize);
}
}
else if(signalType == 1) // SELL signal
{
double bid = m_symbol.Bid();
if(!m_trade.Sell(InpLotSize, _Symbol, bid, slPrice, tpPrice, "ISP EA SELL Signal"))
{
Print("Sell trade failed: ", m_trade.ResultRetcodeDescription());
}
else
{
Print("Sell trade executed at ", bid, " Lot: ", InpLotSize);
}
}
}
//+------------------------------------------------------------------+
//| CloseAllPositions |
//+------------------------------------------------------------------+
void CloseAllPositions()
{
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
string symbol = PositionGetSymbol(i);
ulong magic = PositionGetInteger(POSITION_MAGIC);
if(symbol == _Symbol && magic == InpMagicNumber)
{
ulong ticket = PositionGetInteger(POSITION_TICKET);
double volume = PositionGetDouble(POSITION_VOLUME);
if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
{
// Buy position ko close
m_trade.Sell(volume, _Symbol);
}
else if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
{
// Sell position ko close
m_trade.Buy(volume, _Symbol);
}
if(m_trade.ResultRetcode() == TRADE_RETCODE_DONE)
{
Print("Closed position: Ticket ", ticket);
}
}
}
}
