Article-14782-MQL5-Trailing.../TrailingBySAR_03.mq5

61 lines
5.1 KiB
MQL5
Raw Permalink Normal View History

2026-03-22 16:52:40 +07:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| TrailingBySAR_03.mq5 |
//| Copyright 2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
2026-03-22 17:00:58 +07:00
#property copyright "Copyright 2024, MetaQuotes Ltd."
2026-03-22 16:52:40 +07:00
#property link "https://www.mql5.com"
#property version "1.00"
#define SAR_DATA_INDEX 1 // 10@, A :>B>@>3> ?>;CG05< 40==K5 Parabolic SAR
#include "TrailingsFunc.mqh"
//--- input parameters
input ENUM_TIMEFRAMES InpTimeframeSAR = PERIOD_CURRENT; // Parabolic SAR Timeframe
input double InpStepSAR = 0.02; // Parabolic SAR Step
input double InpMaximumSAR = 0.2; // Parabolic SAR Maximum
input long InpMagic = 123; // Expert Magic Number
//--- global variables
int ExtHandleSAR=INVALID_HANDLE; // EM=4; Parabolic SAR
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- A>740Q< E5=4; Parabolic SAR
ExtHandleSAR=CreateSAR(Symbol(), InpTimeframeSAR, InpStepSAR, InpMaximumSAR);
//--- ?@8 >H81:5 A>740=8O 8=48:0B>@0 2KE>48< A >H81:>9 87 OnInit
if(ExtHandleSAR==INVALID_HANDLE)
return(INIT_FAILED);
//--- CA?5H=>
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- 5A;8 =5 =>2K9 10@ - CE>48< 87 >1@01>BG8:0
if(!IsNewBar())
return;
//--- B@0;8< AB>?K ?>78F89 ?> Parabolic SAR
TrailingByDataInd(ExtHandleSAR, SAR_DATA_INDEX, InpMagic);
}
//+------------------------------------------------------------------+
//| TradeTransaction function |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction& trans,
const MqlTradeRequest& request,
const MqlTradeResult& result)
{
if(trans.type==TRADE_TRANSACTION_DEAL_ADD)
TrailingByDataInd(ExtHandleSAR, SAR_DATA_INDEX, InpMagic);
}
//+------------------------------------------------------------------+