← К каталогу
Исходный код · ID 4810

SMC FUSION

smc_fusion v2_decompiled.mq5

Похожие материалы по тегам

indicator crt with smc levels for tradingview.pineTradingView · 1 общих теговgold_session_liquidity_free_mt5 (1).mq5MQL5 / MetaTrader 5 · 1 общих теговconfluenceforge_pro.mq5TradingView · 1 общих теговidentical candles.mq5MQL5 / MetaTrader 5 · 1 общих теговbattleplan_ciclo_3_tempi.mq4MQL4 / MetaTrader 4 · 1 общих теговvolatility_gold_master.mq5MQL5 / MetaTrader 5 · 1 общих тегов
Вы автор или правообладатель?

Сообщите нам, если считаете, что материал размещён без разрешения.

Краткий обзор

О программе

SMC FUSION — это пользовательский индикатор для MetaTrader 5, реализующий анализ концепций Smart Money. Индикатор обнаруживает 17 различных стратегий SMC (включая FVG, Order Block, Mitigation, Propulsion, Vacuum, Killzone, Swing Failure Pattern и другие), объединяет их в сигналы конфлюэнса с расчётом итогового балла и отображает зоны покупки и продажи на графике.

Для каждой сформированной зоны индикатор рисует уровни входа, стоп-лосса и двух целей (TP1/TP2), а также стрелки и информационные подписи. Доступны фильтр VWAP, определение структурных пробоев BOS/ChoCH, сессионный фильтр и защита от перекрытия зон.

Индикатор имеет встроенный интерактивный панельный интерфейс с кнопками для переключения таймфрейма, фильтра, качества сигнала и отображения целей. Поддерживается отправка уведомлений: звуковых, push-уведомлений и электронной почты.

Настройки программы

НастройкаОписание
InpFilterMode Режим фильтра: выключен или фильтрация по VWAP.
InpShowFilter Отображение линии фильтра VWAP на графике.
InpVWAPCol Цвет линии VWAP на графике.
InpVWAPWidth Толщина линии VWAP на графике.
InpBOSMode Режим работы BOS/ChoCH: выключен, отображение или фильтрация сигналов.
InpBosSwingLen Длина свинга для определения точек разворота структуры.
InpBosBreakMode Режим определения пробоя: по закрытию свечи или по фитилю.
InpBosShowLevels Отображение уровней свинговых максимумов и минимумов на графике.
InpBosBullCol Цвет линий и подписей бычьих структурных пробоев BOS/ChoCH.
InpBosBearCol Цвет линий и подписей медвежьих структурных пробоев BOS/ChoCH.
InpBOSLineWidth Толщина линий структурных пробоев BOS/ChoCH на графике.
InpBOSLabelSize Размер шрифта подписей BOS/ChoCH на графике.
InpSourceTFEnum Временной интервал источника данных для расчётов индикатора.
InpBuyZoneColor Цвет заливки зоны покупки на графике.
InpSellZoneColor Цвет заливки зоны продажи на графике.
InpBuyBorderCol Цвет границы зоны покупки на графике.
InpSellBorderCol Цвет границы зоны продажи на графике.
InpBtnFont Шрифт, используемый для текста на кнопках и подписей панели.
InpBtnFontSize Размер шрифта текста на кнопках и подписях панели.
InpBtnOnColor Цвет активных кнопок на панели управления.
InpBtnOffColor Цвет неактивных кнопок на панели управления.
InpBtnBgColor Цвет фона панели кнопок управления на графике.
InpBtnBorderColor Цвет рамки кнопок управления на графике.
InpBtnX Горизонтальная позиция панели кнопок на графике.
InpBtnY Вертикальная позиция панели кнопок на графике.
InpBtnWidth Ширина кнопок управления на графике в пикселях.
InpBtnHeight Высота кнопок управления на графике в пикселях.
InpBtnSound Включение звукового сигнала при нажатии кнопок на графике.
InpBtnSoundFile Путь к звуковому файлу, воспроизводимому при нажатии кнопок.
InpMaxBars Максимальное количество баров, анализируемых индикатором.
InpPivotLen Длина пивота для определения точек разворота свинга.
InpSwingLookback Количество баров назад для поиска свинговых экстремумов.
InpOBSearchDepth Глубина поиска в истории для обнаружения Order Block.
InpMinBodyRatio Минимальное соотношение тела свечи к её диапазону для распознавания определённых паттернов.
InpLiqSweepATR Множитель ATR для определения уровня ликвидности (сweep ликвидности).
InpRetestBars Количество баров, в течение которых блоки ретеста остаются активными.
InpUseBody Использование тела свечи (открытие-закрытие) вместо диапазона (хай-лоу) для определения границ зон.
InpUseSession Включение сессионного фильтра, ограничивающего анализ торговой сессией.
InpSessionStart Время начала торговой сессии в формате ЧЧ:ММ для сессионного фильтра.
InpSessionEnd Время окончания торговой сессии в формате ЧЧ:ММ для сессионного фильтра.
InpHideMitigated Скрытие зон, которые уже были обработаны ценой (митигированы).
InpHideOverlap Скрытие новых зон, перекрывающих уже существующие зоны противоположного направления.
InpShowLabels Отображение информационных подписей зон на графике.
InpShowMidline Отображение средней линии внутри каждой зоны.
InpExtendBars Количество баров, на которые рисуются зоны за пределами последнего бара.
InpLiveExtendBars Количество баров, на которые продлеваются активные зоны в реальном времени.
InpMaxZonesPerSide Максимальное количество одновременно отображаемых зон в одном направлении (покупка или продажа).
InpBuyArrowCol Цвет стрелки, указывающей точку входа в покупку на графике.
InpSellArrowCol Цвет стрелки, указывающей точку входа в продажу на графике.
InpArrowSize Размер стрелок, отображаемых на графике для обозначения точек входа в позиции.
InpChartLabelSize Размер шрифта информационных подписей на графике.
InpATRLength Период расчёта индикатора ATR, используемого для определения волатильности и расчёта уровней стоп-лосса и целей.
InpSLMultiplier Множитель ATR для расчёта уровня стоп-лосса.
InpTPMultiplier1 Множитель ATR для расчёта первой цели (TP1).
InpTPMultiplier2 Множитель ATR для расчёта второй цели (TP2).
InpShowTPSL Отображение зон и линий TP/SL на графике.
InpProjectionBars Количество баров, на которые проецируются уровни TP/SL от точки входа.
InpTPZoneCol Цвет заливки зоны первой цели на графике.
InpSLZoneCol Цвет заливки зоны стоп-лосса на графике.
InpEntryLineCol Цвет линии входа на графике.
InpTPLineCol Цвет линий целей (TP) на графике.
InpSLLineCol Цвет линии стоп-лосса на графике.
InpCooldownBuy Количество баров карантина между сигналами покупки, предотвращающее частые повторные входы.
InpCooldownSell Количество баров карантина между сигналами продажи, предотвращающее частые повторные входы.
InpEnableAlerts Включение уведомлений о появлении новых сигналов и зон.

Поиск по коду файла

#property strict
#property version "1.00"
#property description "Downloaded for free"

#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0

enum SignalQuality { LOW_3=0, MEDIUM_4=1, HIGH_5=2, ULTRA_6=3 };
enum FilterMode { FILTER_OFF=0, FILTER_VWAP=1 };
enum BOSMode { BOS_OFF=0, BOS_DISPLAY=1, BOS_FILTER=2 };
enum BreakMode { BREAK_CLOSE=0, BREAK_WICK=1 };
enum SourceTimeframe { TF_CURRENT=0, TF_M1=1, TF_M5=2, TF_M15=3, TF_M30=4, TF_H1=5, TF_H4=6, TF_D1=7, TF_W1=8, TF_MN1=9 };

input group "═══ FUSION ENGINE SETTINGS ═══"
input(name="Minimum Signal Quality") SignalQuality InpMinQuality=LOW_3;
input(name="Show Confluence Score on Label") bool InpShowScore=true;
input(name="Confluence Window (bars)") int InpConfluenceWindow=3;

input group "═══ STRATEGY WEIGHTS ═══"
input(name="Weight: Inverse FVG") double InpWeightIFVG=1.0;
input(name="Weight: CRT Retest") double InpWeightCRT=1.2;
input(name="Weight: Order Block") double InpWeightOB=1.5;
input(name="Weight: Mitigation Block") double InpWeightMIT=1.0;
input(name="Weight: Propulsion Block") double InpWeightPROP=1.3;
input(name="Weight: Propulsion Block") double InpWeightVAC=0.8;
input(name="Weight: Vacuum Block") double InpWeightUNI=1.5;
input(name="Weight: Breaker Block") double InpWeightBRK=1.4;
input(name="Weight: FVG Re-Entry") double InpWeightFVG=1.0;
input(name="Weight: Balanced Price Range") double InpWeightBPR=1.2;
input(name="Weight: Killzone OB") double InpWeightKZ=1.3;
input(name="Weight: CE Raid") double InpWeightCE=1.0;
input(name="Weight: Swing Failure Pattern") double InpWeightSFP=1.4;
input(name="Weight: Rejection Block") double InpWeightREJ=1.1;
input(name="Weight: Supply/Demand Flip") double InpWeightSD=1.2;
input(name="Weight: Wyckoff Spring/UT") double InpWeightWY=1.3;
input(name="Weight: MSS Entry") double InpWeightMSS=1.5;

input group "═══ FVG CONFIRMATION ═══"
input(name="Require FVG Confirmation After Signal") bool InpRequireFVGConfirm=true;
input(name="Max Bars to Wait for FVG Confirm") int InpFVGConfirmBars=3;

input group "═══ FILTER SELECTION ═══"
input FilterMode InpFilterMode=FILTER_OFF;
input bool InpShowFilter=true;

input group "═══ VWAP FILTER ═══"
input color InpVWAPCol=55295;
input int InpVWAPWidth=2;

input group "═══ BOS / CHOCH ═══"
input BOSMode InpBOSMode=BOS_OFF;
input int InpBosSwingLen=20;
input BreakMode InpBosBreakMode=BREAK_CLOSE;
input bool InpBosShowLevels=true;
input color InpBosBullCol=7451452;
input color InpBosBearCol=4678655;
input int InpBOSLineWidth=2;
input int InpBOSLabelSize=8;

input group "═══ Source Timeframe ═══"
input SourceTimeframe InpSourceTFEnum=TF_CURRENT;

input group "═══ ZONE COLORS ═══"
input color InpBuyZoneColor=15128749;
input color InpSellZoneColor=11788021;
input color InpBuyBorderCol=16760576;
input color InpSellBorderCol=17919;

input group "═══ SMC Button ═══"
input string InpBtnFont="Arial Bold";
input int InpBtnFontSize=9;
input color InpBtnOnColor=65280;
input color InpBtnOffColor=255;
input color InpBtnBgColor=2629150;
input color InpBtnBorderColor=16748574;
input int InpBtnX=200;
input int InpBtnY=0;
input int InpBtnWidth=60;
input int InpBtnHeight=22;
input bool InpBtnSound=true;
input string InpBtnSoundFile="tick.wav";

input group "═══ Candle Limit ═══"
input int InpMaxBars=2000;

input group "═══ Strategy Parameters ═══"
input int InpPivotLen=3;
input int InpSwingLookback=20;
input int InpOBSearchDepth=15;
input double InpMinBodyRatio=0.3;
input double InpLiqSweepATR=0.2;
input int InpRetestBars=20;
input bool InpUseBody=false;
input bool InpUseSession=false;
input string InpSessionStart="08:00";
input string InpSessionEnd="13:00";

input group "═══ Visual Display ═══"
input bool InpHideMitigated=true;
input bool InpHideOverlap=true;
input bool InpShowLabels=true;
input bool InpShowMidline=false;
input int InpExtendBars=5;
input int InpLiveExtendBars=25;
input int InpMaxZonesPerSide=5;
input color InpBuyArrowCol=16711680;
input color InpSellArrowCol=9639167;

input group "═══ Arrow & Label Size ═══"
input int InpArrowSize=3;
input int InpChartLabelSize=9;

input group "═══ TP/SL Settings (Fusion Optimized) ═══"
input int InpATRLength=14;
input double InpSLMultiplier=1.5;
input double InpTPMultiplier1=2.0;
input double InpTPMultiplier2=3.5;
input bool InpShowTPSL=true;
input int InpProjectionBars=18;
input color InpTPZoneCol=10025880;
input color InpSLZoneCol=4678655;
input color InpEntryLineCol=8421504;
input color InpTPLineCol=32768;
input color InpSLLineCol=255;

input group "═══ Anti-Overlap ═══"
input int InpCooldownBuy=8;
input int InpCooldownSell=8;

input group "═══ Alerts ═══"
input bool InpEnableAlerts=true;
input(name="Send Push Notifications") bool InpEnablePush=true;
input(name="Send Email Notifications") bool InpEnableEmail=false;

struct Signal
{
   bool valid,buy;
   double top,bottom,entry,high,low;
   datetime start,end;
   int strategy,bar;
   double weight;
};
struct Block
{
   double top,bottom;
   bool buy,flipped,used;
   int bar;
   datetime time;
};
struct Fusion
{
   bool valid,buy,mitigated,active,tp1hit,tp2hit,slhit;
   double top,bottom,entry,high,low,score,sl,tp1,tp2,atr;
   datetime start,end,finish;
   int count,bar;
   string names;
};
struct StructureBreak
{
   bool buy,change;
   double price;
   datetime start,end;
};
MqlRates R[];
double VW[];
Signal Pool[];
Block InverseBuy[],InverseSell[],CrtBlocks[],MitBlocks[],BreakBlocks[],GapBlocks[],BprBlocks[],SdBlocks[];
Fusion Zones[],Pending[];
StructureBreak Breaks[];
bool Enabled=true,ShowTargets=true,ForceRefresh=true,Initialized=false;
int FilterSetting=0,BosSetting=0,QualitySetting=0,TimeframeSetting=0;
int LastBuy=-9999,LastSell=-9999,Trend=0,HighBar=-1,LowBar=-1;
double SwingHigh=0,SwingLow=0;
bool HighReady=false,LowReady=false;
string Prefix;
datetime LastSourceBar=0,LastAlert=0;
ENUM_TIMEFRAMES SourceTF=PERIOD_CURRENT;
double Weight(const int id)
{
   double w[17]={InpWeightIFVG,InpWeightCRT,InpWeightOB,InpWeightMIT,InpWeightPROP,InpWeightVAC,InpWeightUNI,InpWeightBRK,InpWeightFVG,InpWeightBPR,InpWeightKZ,InpWeightCE,InpWeightSFP,InpWeightREJ,InpWeightSD,InpWeightWY,InpWeightMSS};
   return id>=0 && id<17?w[id]:1.0;
}
string StrategyName(const int id)
{
   string n[17]={"IF","CRT","OB","MIT","PROP","VAC","UNI","BRK","FVG","BPR","KZ","CE","SFP","REJ","SD","WY","MSS"};
   return id>=0 && id<17?n[id]:"";
}
double Body(const int i){return MathAbs(R[i].close-R[i].open);}
double Range(const int i){return R[i].high-R[i].low;}
bool Bull(const int i){return R[i].close>R[i].open;}
bool Bear(const int i){return R[i].close<R[i].open;}
double ZoneHigh(const int i){return InpUseBody?MathMax(R[i].open,R[i].close):R[i].high;}
double ZoneLow(const int i){return InpUseBody?MathMin(R[i].open,R[i].close):R[i].low;}
double UpperWick(const int i){return R[i].high-MathMax(R[i].open,R[i].close);}
double LowerWick(const int i){return MathMin(R[i].open,R[i].close)-R[i].low;}
double ATR(const int i)
{
   if(i<InpATRLength || i>=ArraySize(R))return 0;
   double sum=0;
   for(int j=i-InpATRLength+1;j<=i;j++)sum+=MathMax(R[j].high-R[j].low,MathMax(MathAbs(R[j].high-R[j-1].close),MathAbs(R[j].low-R[j-1].close)));
   return sum/InpATRLength;
}
double PivotHigh(const int i,const int span)
{
   if(i<span || i+span>=ArraySize(R))return 0;
   for(int j=i-span;j<=i+span;j++)if(j!=i && R[j].high>=R[i].high)return 0;
   return R[i].high;
}
double PivotLow(const int i,const int span)
{
   if(i<span || i+span>=ArraySize(R))return 0;
   for(int j=i-span;j<=i+span;j++)if(j!=i && R[j].low<=R[i].low)return 0;
   return R[i].low;
}
bool Killzone(const int i)
{
   MqlDateTime t;TimeToStruct(R[i].time,t);
   return (t.hour>=2 && t.hour<=5)||(t.hour>=7 && t.hour<=10)||t.hour>=20||t.hour<=0;
}
int MinuteOfDay(const string s)
{
   string a[];if(StringSplit(s,':',a)!=2)return -1;
   int h=(int)StringToInteger(a[0]),m=(int)StringToInteger(a[1]);
   if(h<0||h>23||m<0||m>59)return -1;return h*60+m;
}
bool SessionAllowed(const int i)
{
   if(!InpUseSession)return true;
   MqlDateTime t;TimeToStruct(R[i].time,t);int m=t.hour*60+t.min;
   int a=MinuteOfDay(InpSessionStart),b=MinuteOfDay(InpSessionEnd);
   return a<=b?(m>=a && m<=b):(m>=a || m<=b);
}
void MakeSignal(Signal &s,const int id,const bool buy,const int i,const int start,const double top,const double bottom,const double multiplier=1.0)
{
   ZeroMemory(s);s.valid=true;s.buy=buy;s.strategy=id;s.bar=i;s.top=top;s.bottom=bottom;
   s.entry=R[i].close;s.high=R[i].high;s.low=R[i].low;s.start=R[MathMax(0,start)].time;s.end=R[i].time;s.weight=Weight(id)*multiplier;
}
void PushBlock(Block &a[],const double top,const double bottom,const bool buy,const int bar,const datetime time)
{
   int n=ArraySize(a);ArrayResize(a,n+1);ZeroMemory(a[n]);a[n].top=top;a[n].bottom=bottom;a[n].buy=buy;a[n].bar=bar;a[n].time=time;
}
void TrimBlocks(Block &a[],const int count)
{
   int n=ArraySize(a);if(n>count)ArrayRemove(a,0,n-count);
}
void FromBlock(Signal &s,const Block &b,const int id,const bool buy,const int i)
{
   MakeSignal(s,id,buy,i,b.bar,b.top,b.bottom);s.start=b.time;
}
void DetectIFVG(const int i,const double atr,Signal &s)
{
   if(i<4)return;
   if(R[i].low-R[i-2].high>atr*0.1 && ArraySize(InverseBuy)<40)PushBlock(InverseBuy,R[i].low,R[i-2].high,true,i-1,R[i-1].time);
   if(R[i-2].low-R[i].high>atr*0.1 && ArraySize(InverseSell)<40)PushBlock(InverseSell,R[i-2].low,R[i].high,false,i-1,R[i-1].time);
   for(int k=ArraySize(InverseBuy)-1;k>=0;k--)
   {
      if(InverseBuy[k].used)continue;
      if(i-InverseBuy[k].bar>80){InverseBuy[k].used=true;continue;}
      if(i-InverseBuy[k].bar>1 && R[i].close<InverseBuy[k].bottom){FromBlock(s,InverseBuy[k],0,false,i);InverseBuy[k].used=true;break;}
   }
   if(!s.valid)for(int k=ArraySize(InverseSell)-1;k>=0;k--)
   {
      if(InverseSell[k].used)continue;
      if(i-InverseSell[k].bar>80){InverseSell[k].used=true;continue;}
      if(i-InverseSell[k].bar>1 && R[i].close>InverseSell[k].top){FromBlock(s,InverseSell[k],0,true,i);InverseSell[k].used=true;break;}
   }
   TrimBlocks(InverseBuy,30);TrimBlocks(InverseSell,30);
}
void DetectCRT(const int i,const double atr,const bool breakUp,const bool breakDown,Signal &s)
{
   if(i<3)return;
   for(int side=0;side<2;side++)
   {
      bool buy=side==0;int pivot=buy?HighBar:LowBar;
      if(!(buy?breakUp:breakDown)||pivot<=0||pivot>=ArraySize(R)||ArraySize(CrtBlocks)>=25)continue;
      int start=pivot;
      for(int j=pivot;j>=MathMax(0,pivot-8);j--)if(buy?Bear(j):Bull(j)){start=j;break;}
      PushBlock(CrtBlocks,R[start].high,R[start].low,buy,i,R[MathMax(0,i-3)].time);
   }
   for(int k=ArraySize(CrtBlocks)-1;k>=0;k--)
   {
      if(CrtBlocks[k].used)continue;
      int age=i-CrtBlocks[k].bar;
      if(age>InpRetestBars){CrtBlocks[k].used=true;continue;}
      if(age<=1)continue;
      double hi=CrtBlocks[k].top,lo=CrtBlocks[k].bottom;
      bool ok=CrtBlocks[k].buy?(R[i].low<=hi+atr*.3 && R[i].low>=lo-atr*.3 && R[i].close>lo):(R[i].high>=lo-atr*.3 && R[i].high<=hi+atr*.3 && R[i].close<hi);
      if(ok){FromBlock(s,CrtBlocks[k],1,CrtBlocks[k].buy,i);CrtBlocks[k].used=true;break;}
   }
   TrimBlocks(CrtBlocks,20);
}
void DetectOB(const int i,const double atr,Signal &s,const int id=2)
{
   if(i<InpOBSearchDepth+(id==10?3:2))return;
   if(id==10 && !Killzone(i))return;
   double threshold=id==10?0.8:1.0;
   if(Body(i)<atr*threshold || (!Bull(i)&&!Bear(i)))return;
   bool buy=Bull(i);
   for(int j=i-1;j>=MathMax(0,i-InpOBSearchDepth);j--)
   {
      if(id==10 && !Killzone(j))continue;
      if(!(buy?Bear(j):Bull(j)) || Body(j)<=_Point)continue;
      if(Body(j)/MathMax(_Point,Range(j))<InpMinBodyRatio)continue;
      MakeSignal(s,id,buy,i,j,ZoneHigh(j),ZoneLow(j),id==2 && Body(i)>=1.5*atr?1.3:1.0);return;
   }
}
void DetectFlip(const int i,const double atr,Signal &s,Block &blocks[],const int id)
{
   if(i<InpOBSearchDepth+(id==7?3:2))return;
   double threshold=id==7?0.8:0.8;
   if(Body(i)>=atr*threshold && (Bull(i)||Bear(i)))
   {
      bool buy=Bull(i);
      for(int j=i-1;j>=MathMax(0,i-InpOBSearchDepth);j--)
      {
         if(!(buy?Bear(j):Bull(j)))continue;
         if(id==7 && Body(j)/MathMax(_Point,Range(j))<InpMinBodyRatio*0.7)continue;
         PushBlock(blocks,ZoneHigh(j),ZoneLow(j),buy,j,R[j].time);break;
      }
   }
   for(int k=ArraySize(blocks)-1;k>=0;k--)
   {
      if(blocks[k].used)continue;
      if(i-blocks[k].bar>500){blocks[k].used=true;continue;}
      if(!blocks[k].flipped)
      {
         if(blocks[k].buy?R[i].close<blocks[k].bottom:R[i].close>blocks[k].top)blocks[k].flipped=true;
         continue;
      }
      bool buy=!blocks[k].buy;
      bool ok=buy?(R[i].low<=blocks[k].top && (id==3?R[i].close>=blocks[k].bottom:R[i].close>blocks[k].bottom)):(R[i].high>=blocks[k].bottom && (id==3?R[i].close<=blocks[k].top:R[i].close<blocks[k].top));
      if(ok){FromBlock(s,blocks[k],id,buy,i);blocks[k].used=true;break;}
   }
   TrimBlocks(blocks,60);
}
void DetectPropulsion(const int i,const double atr,Signal &s)
{
   if(i<InpOBSearchDepth+3)return;
   bool buy=R[i].low>R[i-2].high,sell=R[i].high<R[i-2].low;
   if((!buy&&!sell)||Body(i)<atr||!(buy?Bull(i):Bear(i)))return;
   double hi=buy?R[i].low:R[i-2].low,lo=buy?R[i-2].high:R[i].high;
   for(int j=i-1;j>=MathMax(0,i-InpOBSearchDepth);j--)
   {
      if(!(buy?Bear(j):Bull(j)))continue;
      double top=MathMax(hi,ZoneHigh(j)),bottom=MathMin(lo,ZoneLow(j));
      if(bottom<top){MakeSignal(s,4,buy,i,j,top,bottom);return;}
   }
}
void DetectVacuum(const int i,const double atr,Signal &s)
{
   if(i<3)return;
   if(R[i].low-R[i-2].high>=atr)MakeSignal(s,5,true,i,i-2,R[i].low,R[i-2].high);
   else if(R[i-2].low-R[i].high>=atr)MakeSignal(s,5,false,i,i-2,R[i-2].low,R[i].high);
}
void DetectUnicorn(const int i,const double atr,const bool up,const bool down,Signal &s)
{
   if(i<4)return;
   for(int side=0;side<2;side++)
   {
      bool buy=side==0;double pivot=buy?SwingHigh:SwingLow;
      if(!(buy?up:down)||pivot<=0)continue;
      for(int j=i;j>=MathMax(2,i-4);j--)
      {
         double hi=buy?R[j].low:R[j-2].low,lo=buy?R[j-2].high:R[j].high;
         if(hi>lo && MathAbs((hi+lo)*.5-pivot)<=atr*1.5){MakeSignal(s,6,buy,i,j-2,hi,lo);return;}
      }
   }
}
void DetectFVG(const int i,const double atr,Signal &s)
{
   if(i<5)return;
   if(R[i-1].low-R[i-3].high>atr*.2)PushBlock(GapBlocks,R[i-1].low,R[i-3].high,true,i-2,R[i-2].time);
   if(R[i-3].low-R[i-1].high>atr*.2)PushBlock(GapBlocks,R[i-3].low,R[i-1].high,false,i-2,R[i-2].time);
   for(int k=ArraySize(GapBlocks)-1;k>=0;k--)
   {
      if(GapBlocks[k].used)continue;
      int age=i-GapBlocks[k].bar;if(age>40){GapBlocks[k].used=true;continue;}if(age<=1)continue;
      bool buy=GapBlocks[k].buy;
      bool ok=buy?(R[i].low<=GapBlocks[k].top && R[i].close>GapBlocks[k].bottom && Bull(i)):(R[i].high>=GapBlocks[k].bottom && R[i].close<GapBlocks[k].top && Bear(i));
      if(ok){FromBlock(s,GapBlocks[k],8,buy,i);GapBlocks[k].used=true;break;}
   }
   TrimBlocks(GapBlocks,70);
}
void DetectBPR(const int i,const double atr,Signal &s)
{
   if(i<5)return;
   if(R[i-1].low>R[i-3].high)PushBlock(BprBlocks,R[i-1].low,R[i-3].high,true,i-2,R[i-2].time);
   if(R[i-1].high<R[i-3].low)PushBlock(BprBlocks,R[i-3].low,R[i-1].high,false,i-2,R[i-2].time);
   int n=ArraySize(BprBlocks);
   for(int k=n-1;k>=MathMax(0,n-20)&&!s.valid;k--)
   {
      if(BprBlocks[k].used)continue;
      if(i-BprBlocks[k].bar>25){BprBlocks[k].used=true;continue;}
      for(int j=k-2;j>=MathMax(0,k-16);j--)
      {
         if(BprBlocks[j].used || BprBlocks[j].buy==BprBlocks[k].buy)continue;
         double top=MathMin(BprBlocks[k].top,BprBlocks[j].top),bottom=MathMax(BprBlocks[k].bottom,BprBlocks[j].bottom);
         if(top<=bottom)continue;
         bool buy=BprBlocks[k].buy;
         bool ok=buy?(R[i].low<=top+atr*.3 && R[i].close>bottom):(R[i].high>=bottom-atr*.3 && R[i].close<top);
         if(ok){MakeSignal(s,9,buy,i,BprBlocks[j].bar,top,bottom);BprBlocks[j].used=true;BprBlocks[k].used=true;break;}
      }
   }
   TrimBlocks(BprBlocks,100);
}
void DetectCE(const int i,const double atr,Signal &s)
{
   if(i<6)return;
   for(int j=i-3;j>=MathMax(2,i-20);j--)
   {
      double hi=R[j].low,lo=R[j-2].high,mid=(hi+lo)*.5;
      if(hi>lo && hi-lo>=atr*.2 && R[i].low<=mid+atr*.15 && R[i].low>=lo-atr*.15 && R[i].close>mid && Bull(i))
      {MakeSignal(s,11,true,i,j,hi,mid-atr*.1);return;}
      hi=R[j-2].low;lo=R[j].high;mid=(hi+lo)*.5;
      if(hi>lo && hi-lo>=atr*.2 && R[i].high>=mid-atr*.15 && R[i].high<=hi+atr*.15 && R[i].close<mid && Bear(i))
      {MakeSignal(s,11,false,i,j,mid+atr*.1,lo);return;}
   }
}
void SwingExtremes(const int i,double &hi,double &lo,int &ih,int &il)
{
   hi=0;lo=DBL_MAX;ih=-1;il=-1;
   for(int j=i-2;j>=MathMax(0,i-InpSwingLookback);j--)
   {
      double h=PivotHigh(j,InpPivotLen),l=PivotLow(j,InpPivotLen);
      if(h>0 && h>hi){hi=h;ih=j;}if(l>0 && l<lo){lo=l;il=j;}
   }
}
void DetectSFP(const int i,const double atr,Signal &s)
{
   if(i<InpSwingLookback+2)return;
   double hi,lo;int ih,il;SwingExtremes(i,hi,lo,ih,il);
   double uw=UpperWick(i),lw=LowerWick(i),body=Body(i);
   if(hi>0 && R[i].high>hi && R[i].close<hi && R[i].open<hi && uw>body*.5 && uw>atr*.2)
      MakeSignal(s,12,false,i,i,R[i].high,MathMax(R[i].open,R[i].close),uw>atr*.5?1.3:1.0);
   else if(il>=0 && R[i].low<lo && R[i].close>lo && R[i].open>lo && lw>body*.5 && lw>atr*.2)
      MakeSignal(s,12,true,i,i,MathMin(R[i].open,R[i].close),R[i].low,lw>atr*.5?1.3:1.0);
}
void DetectRejection(const int i,const double atr,Signal &s)
{
   if(i<InpSwingLookback+2 || Range(i)<atr*.5)return;
   double hi=0,lo=DBL_MAX;
   for(int j=i-1;j>=MathMax(0,i-InpSwingLookback);j--){hi=MathMax(hi,R[j].high);lo=MathMin(lo,R[j].low);}
   double uw=UpperWick(i),lw=LowerWick(i),body=Body(i),range=Range(i);
   if(uw>range*.5 && uw>body*1.5 && R[i].high>=hi-atr*.3)
      MakeSignal(s,13,false,i,i,R[i].high,MathMax(R[i].open,R[i].close),uw>range*.65?1.2:1.0);
   else if(lw>range*.5 && lw>body*1.5 && R[i].low<=lo+atr*.3)
      MakeSignal(s,13,true,i,i,MathMin(R[i].open,R[i].close),R[i].low,lw>range*.65?1.2:1.0);
}
void DetectSupplyDemand(const int i,const double atr,Signal &s)
{
   if(i<6)return;
   if(Body(i)>=atr*.8 && (Bull(i)||Bear(i)))
      for(int j=i-1;j>=MathMax(0,i-5);j--)if(Body(j)<atr*.3){PushBlock(SdBlocks,R[j].high,R[j].low,Bear(i),j,R[j].time);break;}
   for(int k=ArraySize(SdBlocks)-1;k>=0;k--)
   {
      if(SdBlocks[k].used)continue;
      if(i-SdBlocks[k].bar>200){SdBlocks[k].used=true;continue;}
      if(!SdBlocks[k].flipped)
      {
         if(!SdBlocks[k].buy && R[i].close<SdBlocks[k].bottom){SdBlocks[k].flipped=true;SdBlocks[k].buy=true;}
         if(SdBlocks[k].buy && R[i].close>SdBlocks[k].top){SdBlocks[k].flipped=true;SdBlocks[k].buy=false;}
         continue;
      }
      bool buy=!SdBlocks[k].buy;
      bool ok=buy?(R[i].low<=SdBlocks[k].top && R[i].close>SdBlocks[k].bottom):(R[i].high>=SdBlocks[k].bottom && R[i].close<SdBlocks[k].top);
      if(ok){FromBlock(s,SdBlocks[k],14,buy,i);SdBlocks[k].used=true;break;}
   }
   TrimBlocks(SdBlocks,80);
}
void DetectWyckoff(const int i,const double atr,Signal &s)
{
   if(i<25)return;
   int start=MathMax(0,i-20);double hi=0,lo=DBL_MAX;
   for(int j=start;j<i-2;j++){hi=MathMax(hi,R[j].high);lo=MathMin(lo,R[j].low);}
   double range=hi-lo;if(range<atr*2 || range>atr*8)return;
   double depth=lo-R[i].low;
   if(R[i].low<lo && R[i].close>lo && R[i].close<hi && depth>atr*.1 && depth<atr*1.5)
      MakeSignal(s,15,true,i,start,lo+range*.15,R[i].low,depth>atr*.3 && Bull(i)?1.3:1.0);
   else
   {
      depth=R[i].high-hi;
      if(R[i].high>hi && R[i].close<hi && R[i].close>lo && depth>atr*.1 && depth<atr*1.5)
         MakeSignal(s,15,false,i,start,R[i].high,hi-range*.15,depth>atr*.3 && Bear(i)?1.3:1.0);
   }
}
void DetectMSS(const int i,const double atr,Signal &s)
{
   if(i<InpSwingLookback+5)return;
   double hi,lo;int ih,il;SwingExtremes(i,hi,lo,ih,il);
   if(il>0 && Bull(i) && Body(i)>atr && R[i].close>lo)
      for(int j=i-1;j>=MathMax(il+1,i-8);j--)if(R[j].low<lo){MakeSignal(s,16,true,i,il,lo+atr*.3,lo-atr*.3,Body(i)>atr*1.5?1.3:1.0);return;}
   if(ih>0 && Bear(i) && Body(i)>atr && R[i].close<hi)
      for(int j=i-1;j>=Ma

Показано первые 50% кода (символов: 36101)