Supertrend by KivancOzbilgic MT4
- Indicators
- Yashar Seyyedin
- Version: 1.10
- Updated: 1 June 2023
- Activations: 5
To get access to MT5 version please click here.
- This is the exact conversion from TradingView: "Supertrend" by "KivancOzbilgic".
- This is a light-load processing and non-repaint indicator.
- Highlighter option isn't available in MT4 version.
- You can message in private chat for further changes you need.
Here is the source code of a simple Expert Advisor operating based on signals from Supertrend.
#property strict input string EA_Setting=""; input int magic_number=1234; input double fixed_lot_size=0.01; // select fixed lot size enum ENUM_SOURCE{OPEN, CLOSE, HIGH, LOW, HL2, HLC3, OHLC4, HLCC4}; input string SuperTrend_Setting=""; input int Periods = 10; //ATR Period input ENUM_SOURCE src = HL2; //Source input double Multiplier = 3; //ATR Multiplier input bool changeATR= true; //Change ATR Calculation Method ? input bool showsignals = false; //Show Buy/Sell Signals ? void OnTick() { if(!isNewBar()) return; bool buy_condition=true; buy_condition &= (BuyCount()==0); buy_condition &= (IsSuperTrendBuy(1)); if(buy_condition) { CloseSell(); Buy(); } bool sell_condition=true; sell_condition &= (SellCount()==0); sell_condition &= (IsSuperTrendSell(1)); if(sell_condition) { CloseBuy(); Sell(); } } bool IsSuperTrendBuy(int index) { double value_buy=iCustom(_Symbol, PERIOD_CURRENT, "Market\\Supertrend by KivancOzbilgic MT4", Periods, src, Multiplier, changeATR, showsignals, 8, index); return value_buy!=EMPTY_VALUE; } bool IsSuperTrendSell(int index) { double value_sell=iCustom(_Symbol, PERIOD_CURRENT, "Market\\Supertrend by KivancOzbilgic MT4", Periods, src, Multiplier, changeATR, showsignals, 9, index); return value_sell!=EMPTY_VALUE; } int BuyCount() { int counter=0; for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i, SELECT_BY_POS)==false) continue; if(OrderSymbol()!=_Symbol) continue; if(OrderMagicNumber()!=magic_number) continue; if(OrderType()==OP_BUY) counter++; } return counter; } int SellCount() { int counter=0; for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i, SELECT_BY_POS)==false) continue; if(OrderSymbol()!=_Symbol) continue; if(OrderMagicNumber()!=magic_number) continue; if(OrderType()==OP_SELL) counter++; } return counter; } void Buy() { if(OrderSend(_Symbol, OP_BUY, fixed_lot_size, Ask, 3, 0, 0, NULL, magic_number, 0, clrNONE)==-1) { Print("Error Executing Order: ", GetLastError()); //ExpertRemove(); } } void Sell() { if(OrderSend(_Symbol, OP_SELL, fixed_lot_size, Bid, 3, 0, 0, NULL, magic_number, 0, clrNONE)==-1) { Print("Error Executing Order: ", GetLastError()); //ExpertRemove(); } } void CloseBuy() { for(int i=OrdersTotal()-1;i>=0;i--) { if(OrderSelect(i, SELECT_BY_POS)==false) continue; if(OrderSymbol()!=_Symbol) continue; if(OrderMagicNumber()!=magic_number) continue; if(OrderType()==OP_BUY) if(OrderClose(OrderTicket(), OrderLots(), Bid, 3, clrNONE)==false) { Print("Error Closing Position: ", GetLastError()); } } } void CloseSell() { for(int i=OrdersTotal()-1;i>=0;i--) { if(OrderSelect(i, SELECT_BY_POS)==false) continue; if(OrderSymbol()!=_Symbol) continue; if(OrderMagicNumber()!=magic_number) continue; if(OrderType()==OP_SELL) if(OrderClose(OrderTicket(), OrderLots(), Ask, 3, clrNONE)==false) { Print("Error Closing Position: ", GetLastError()); } } } datetime timer=NULL; bool isNewBar() { datetime candle_start_time= (int)(TimeCurrent()/(PeriodSeconds()))*PeriodSeconds(); if(timer==NULL) {} else if(timer==candle_start_time) return false; timer=candle_start_time; return true; }