RenkoRsiEma
RenkoRsiEma

RenkoRsiEma最新版

更新日期:
2022-03-16
分类标签:
语言:
中文
平台:
没限制

42 人已下载 手机查看

描述文字

//+——————————————————————+
//| RenkoRsiEma.mq4 |
//| Copyright 2016, AutoBots |
//| mailto://forex.autobots@gmail.com |
//+——————————————————————+
#property copyright “Copyright 2016, AutoBots”
#property link “mailto://forex.autobots@gmail.com”
#property version “1.00”
#property strict

#include <stderror.mqh>
#include <stdlib.mqh>

 

enum enumON_Off{
On, //Turn-On
Off, //Turn-Off
};

enum enumOpenTipe{
tick, //On Tick
bar, //On Close (New Bar)
};

enum enumModeTP{
targetPips, //Target in Pips
targetMoney, //Target in Money
};

enum enumKatTarget{
group, //Grouping Buy and Sell
separate, //Buy and Sell separately
};

input string strInformation = “EA / Robot Renko RSI EMA AutoBots”; //Information : _______________________
//input string str1 = “Min. $100”; //Initial Deposit (Recommended $300)
//input string str2 = “Effective in M15”; //Time Frame
//input string str21 = “GBP/USD”; //Pair
//input string str3 = “Low 0.01, Medium 0.02, High 0.04”; //Risk Based on Volume (lot)
input string str4 = “forex.autobots@gmail.com”; //Contact Us
input string strSeperator = “_________________________________”; //_________________________________

input string strAutoTrading = “_________________________________”; //AutoTrading Setting : ________________
input enumON_Off IN_AutoTrading = 0; //Auto Trading
input enumON_Off IN_ForceCloseAll = 1; //Close All Orders When Auto Trading Off
bool ExtAllowAutoTrade = true; //AutoTrading Mode
bool ExtAllowOpSell = true; //Auto Sell
bool ExtAllowOpBuy = true; //Auto Buy

input string strTrading = “_________________________________”; //Trading Setting : ________________
input double IN_Vol =0.1; //Volume (lots)

//Indikator
extern int IN_PeriodTrend = 200; //EMA Main Chart
extern int rsiPeriod = 7; //RSI Period
extern int rsiApplyPrice = 0; //RSI Applied Price
extern int emaPeriod = 14; //EMA Fast
extern int Offset = 50; //Offset

input double IN_Step = 0.02; //SAR – Price increment step
input double IN_Maximum = 0.2; //SAR – Maximum value of step

input enumKatTarget IN_KategoriTarget = 0; //Target Mode
input enumModeTP IN_ModeTP = 0; //Target Type
input int IN_TargetPips = 15; //Target Pips
input double IN_TargetMoney = 1.5; //Target in Money ($)
//input int IN_Fix_TP = 20; //Take Profit (pips)
input int IN_StopLoss = 0; //Stop Loss (pips)
input int IN_JarakSameOrder=30; //Open New Order Every (pips)

 

input string strEAAuth = “_________________________________”; //Authentication : _________________
input string IN_AuthVoucherID = “— by request to forex.autobots@gmail.com —“; //Voucher ID
int IN_LamaTunggu_Insta = 1; //300 detik
enumOpenTipe IN_OpenTipe= 1; //Open Tipe

//dari indikator
double arrCrossUp[150];
double arrCrossDown[150];
double arrRSI[150];
double arrRSIFastMA[150];
//——————————–

double P_MyPoint;
int P_Slippage=3;
int P_MagicNum=889;
int P_TimeFrame;
double P_Spread;
datetime P_LastAlert;

string EACode=”RS”; //Renko Scalper (Renko, RSI, EMA)
string EANumber = “27”;

//+——————————————————————+
//| Set chart scale (from 0 to 5). |
//+——————————————————————+
bool ChartScaleSet(const long value,const long chart_ID=0)
{
//— reset the error value
ResetLastError();
//— set property value
if(!ChartSetInteger(chart_ID,CHART_SCALE,0,value))
{
//— display the error message in Experts journal
Print(__FUNCTION__+”, Error Code = “,GetLastError());
return(false);
}
//— successful execution
return(true);
}

//+——————————————————————+
//| Inisialisasi Chart |
//+——————————————————————+
void InitChart(){
//—
// Setting Chart
//if (P_TimeFrame == 0) Alert (“Belum Init TimeFrame”);
ChartSetSymbolPeriod(0,NULL, P_TimeFrame);

ChartScaleSet(2); //scale ke ukuran 4(perbesar) value : 0-5
ChartSetInteger(0,CHART_MODE,CHART_CANDLES);
ChartSetInteger(0,CHART_AUTOSCROLL,0, true);
ChartSetInteger(0,CHART_SHIFT,0, true);
ChartSetInteger(0, CHART_SHOW_GRID, false);

ChartSetInteger(0, CHART_COLOR_CANDLE_BEAR, clrBlack);
ChartSetInteger(0, CHART_COLOR_CHART_DOWN, clrLime);
ChartSetInteger(0, CHART_COLOR_CANDLE_BULL, clrWhiteSmoke);
ChartSetInteger(0, CHART_COLOR_CHART_UP, clrLime);

// ChartSetInteger(0, CHART_COLOR_CANDLE_BEAR, clrBlack);
// ChartSetInteger(0, CHART_COLOR_CHART_DOWN, clrWhite);
// ChartSetInteger(0, CHART_COLOR_CANDLE_BULL, clrWhiteSmoke);
// ChartSetInteger(0, CHART_COLOR_CHART_UP, clrWhite);
//

//ChartSetInteger(0, CHART_COLOR_BACKGROUND, clrWhite);
//ChartSetInteger(0, CHART_COLOR_, clrBlack);

}

int GenerateMagicNumber()
{
string TF, UniqueNumber;
string Simbol=””;
string MN;
string pesanErr=””;
int period;

//int P_MN = 100104001;
//Magic Number dg Format: aabbccddd
//Format :
//aabbccddee
//aa: EANumber 10
//bb: Currency 01:GBPUSD
//cc: TimeFrame 04: M30 01:M1 02:M5 03:M15 04:M30 05:H1 06:H4 07:D1 08:W1 09:MN
//ddd: Number, 001 could be any number.

UniqueNumber = “0”; // + ExtIDMN;

Simbol = Symbol();
period = ChartPeriod();
TF = IntegerToString(period,0);
if (StringLen(TF) < 2 ) TF = “0” + TF;

if (Simbol == “GBPUSD” )Simbol = “01”;
if (Simbol == “USDCHF” )Simbol = “02”;
if (Simbol == “USDJPY” )Simbol = “03”;
if (Simbol == “EURUSD” )Simbol = “04”;
if (Simbol == “AUDUSD” )Simbol = “05”;
if (Simbol == “USDCAD” )Simbol = “06”;
if (Simbol == “NZDUSD” )Simbol = “07”;
if (Simbol == “AUDCAD” )Simbol = “08”;
if (Simbol == “EURCHF” )Simbol = “09”;
if (Simbol == “CADCHF” )Simbol = “11”;
if (Simbol == “EURJPY” )Simbol = “12”;
if (Simbol == “EURAUD” )Simbol = “13”;
if (Simbol == “CADJPY” )Simbol = “14”;
if (Simbol == “NZDJPY” )Simbol = “15”;
if (Simbol == “GBPAUD” )Simbol = “16”;
if (Simbol == “EURGBP” )Simbol = “17”;
if (Simbol == “CHFJPY” )Simbol = “18”;
if (Simbol == “GBPNZD” )Simbol = “19”;
if (Simbol == “GBPJPY” )Simbol = “20”;
if (Simbol == “XAUUSD” )Simbol = “21”;
if (Simbol == “AUDJPY” )Simbol = “22”;
if (Simbol == “AUDNZD” )Simbol = “23”;
if (Simbol == “AUDCHF” )Simbol = “24”;
if (Simbol == “EURCAD” )Simbol = “25”;
if (Simbol == “GBPCHF” )Simbol = “26”;
if (Simbol == “NZDCHF” )Simbol = “27”;
if (StringLen(Simbol) > 2) {
pesanErr = “Pair: ” + Simbol + ” tidak terdaftar dalam program ” + EACode + “. AutoTrade dinonaktifkan”;
Simbol = “00”;
Alert (pesanErr);
ExtAllowAutoTrade = false;
}

MN = EANumber + Simbol + TF + UniqueNumber;
if (pesanErr != “”){
errMsg (pesanErr);
}

return MN;

}

void errMsg(string pesanErr){
Print (pesanErr);
}

//+——————————————————————+
//| Expert initialization function |
//+——————————————————————+
int OnInit()
{
InitChart();
//—- indicators
Comment(“Hello ” + AccountName() + “\n”);

SetLabel(“lblCreator”, “Created by AutoBots”, 5, 40,Gold,”Arial”,8,0);
SetLabel(“lblSupport”, “Support: forex.autobots@gmail.com”, 5, 52, Gold, “Arial”,8,0);

P_TimeFrame = PERIOD_CURRENT; // GetTimeFrame(IN_TimeFrame);
P_Spread = MarketInfo(Symbol(), MODE_SPREAD) * Point;
P_MagicNum = GenerateMagicNumber();

if ((Digits % 2) == 1 ) P_MyPoint = 10 * Point;
else P_MyPoint = Point;

//AutoTrading Off =1 dan Force Close All = 0
if ((IN_AutoTrading==1) && (IN_ForceCloseAll==0)){
int tOrder;
double closePrice=0.0;
tOrder = OrdersTotal();
int ans = MessageBox(“Are You Sure to Force Close All Orders?”, “Close All”, MB_YESNO);
if (ans == IDYES){
//Yes
for (int i=tOrder-1; i>=0; i–){
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderMagicNumber() == P_MagicNum){
if (OrderType() == OP_BUY) closePrice = Bid;
if (OrderType() == OP_SELL) closePrice = Ask;
OrderClose(OrderTicket(), OrderLots(), closePrice, P_Slippage, clrGold);
}
}
ExtAllowAutoTrade = false;
Alert (“All Orders have been closed”);

}else if (ans == IDNO){
//NO
Alert (“Close All Orders cancelled”);
}
}
//++++++++++ end kontrol AutoTrading OnOff ++++++++++++++++++

EventSetTimer(5);
//OnTick();
return(INIT_SUCCEEDED);
}
//+——————————————————————+
//| Expert deinitialization function |
//+——————————————————————+
void OnDeinit(const int reason)
{
//—
//ClearObjects();
Comment(“”);
EventKillTimer();
}
//+——————————————————————+
//| Expert tick function |
//+——————————————————————+
void OnTick()
{
//—
//static int k=0;
//k++;
//Alert (“Dalam Tick ” + k);

//Cek AutoTrading
if (IN_AutoTrading == 1){ //1=off, 0 = on

int tOrder;
bool flagOrderOnMarket = false;
tOrder = OrdersTotal();
for (int i=tOrder-1; i>=0; i–){
if (OrderMagicNumber() == P_MagicNum){
flagOrderOnMarket = true;
break;
}
}

ExtAllowAutoTrade = flagOrderOnMarket;

}else if (IN_AutoTrading == 0){ //AutoTrading On
//Cek authentication
ExtAllowAutoTrade = CekAuthentication();
}
//+++++++++++++++++++++++++++++

if (ExtAllowAutoTrade==true){
static int cBars=0;
bool newBar=false;

if (Bars != cBars){
newBar = true;
cBars = Bars;
} else newBar = false;
if (
(IN_OpenTipe == 0) ||
(newBar))
{
int orderType=-1;
orderType = FindSignal(P_TimeFrame);
OpenOrder(orderType);

}
}

InfoAccount();

}
//+——————————————————————+

void OnTimer(){
OnTick();
}

datetime GetTglExpired(string voucherID){
datetime tglExpired=D’2020.02.01′;

//code here… 😉

return tglExpired;
}

 

bool CekAuthentication(){
bool flag;
string strVoucherID=””;
datetime tglExpired=D’1977.09.18′;

tglExpired = GetTglExpired(IN_AuthVoucherID);

if (TimeCurrent() <= tglExpired){
flag = true;
//SetLabel(“lblStatusEA”, “EA / Robot Active (Expired on ” + TimeToString(tglExpired, TIME_DATE) + “)” , 5, 25, clrWhiteSmoke, “Arial”, 8, 0);
}else{
flag = false;
SetLabel(“lblStatusEA”, “EA / Robot Expired”, 5, 25, clrRed, “Arial”, 8, 0);
}

return flag;
}

 

 

int FindSignal(int tf){
int signal = -1;

// int limit;
// //int counted_bars = IndicatorCounted();
// int i;
//
// //if( counted_bars < 0 ) return( -1 );
// //if( counted_bars > 0 ) counted_bars –;
// //limit = Bars – counted_bars;
//
// limit = 150; //Sesuaikan dengan data Array utk arrRSI, arrRSIFastMA, dll
//
// //Feeding Data______________________________
// for( i = limit – 1; i >= 0; i — )
// arrRSI[i] = iRSI(NULL,0,rsiPeriod,rsiApplyPrice,i);
//
//
// for( i = limit – 1; i >= 0; i — ){
// arrRSIFastMA[i] = iMAOnArray( arrRSI, 0, emaPeriod, MODE_EMA, 0, i );
// //Alert (“Nilai arr EMA” + i + ” : ” + arrRSIFastMA[i]);
// }
////+——————————————————————+
//
//
//// for( i = limit – 1; i >= 0; i — )
//// {
//// if((arrRSI[i+1] > arrRSIFastMA[i+1]) && (arrRSI[i+2] < arrRSIFastMA[i+2]))
//// {
//// arrCrossUp[i+1] = Offset;
//// }
////
//// if((arrRSI[i+1] < arrRSIFastMA[i+1]) && (arrRSI[i+2] > arrRSIFastMA[i+2]))
//// {
//// arrCrossDown[i+1] = Offset;
//// }
//// }

double sar = iSAR(Symbol(), PERIOD_CURRENT, IN_Step, IN_Maximum, 0);

double lastRSI = iCustom(Symbol(), PERIOD_CURRENT, “RSI DANNY”, rsiPeriod, emaPeriod, rsiApplyPrice, Offset, 0, 2);
double lastEMA = iCustom(Symbol(), PERIOD_CURRENT, “RSI DANNY”, rsiPeriod, emaPeriod, rsiApplyPrice, Offset, 1, 2);

double currRSI = iCustom(Symbol(), PERIOD_CURRENT, “RSI DANNY”, rsiPeriod, emaPeriod, rsiApplyPrice, Offset, 0, 1);
double currEMA = iCustom(Symbol(), PERIOD_CURRENT, “RSI DANNY”, rsiPeriod, emaPeriod, rsiApplyPrice, Offset, 1, 1);

//Alert (DoubleToStr(a,2) + ” \n” + DoubleToStr(b, 2));
//Alert (DoubleToStr(arrRSI[1],2) + ” \n” + DoubleToStr(arrRSIFastMA[1], 2) + ” \n” + DoubleToStr(arrRSI[0],2) + ” \n” + DoubleToStr(arrRSIFastMA[0],2));

double mainEMA = iMA(Symbol(), tf, IN_PeriodTrend, 0, MODE_EMA, PRICE_CLOSE, 1);
datetime x;
double y;
if(
//((arrRSI[1] > arrRSIFastMA[1]) && (arrRSI[2] < arrRSIFastMA[2]))
((currRSI > currEMA) && (lastRSI < lastEMA))
&& (Close[1] > mainEMA)
&& (sar < Close[0])
){
//arrCrossUp[i+1] = Offset;
signal = OP_BUY;
x = Time[0];
y = Open[0] – (10*Point);
}

if(
//((arrRSI[1] < arrRSIFastMA[1]) && (arrRSI[2] > arrRSIFastMA[2]))
((currRSI < currEMA) && (lastRSI > lastEMA))
&& (Close[1] < mainEMA)
&& (sar > Close[0])
){
//arrCrossDown[i+1] = Offset;
signal = OP_SELL;
x = Time[0];
y = Open[0] + (10*Point);
}

if (signal >= 0) DrawSignal(signal, x, y);
//Print (“Bid ” + Bid + ” Close 0 : ” + Close[0] + ” ema: ” + mainEMA);
return signal;
}

void DrawSignal(int orderType, datetime x, double y){
string name=””;
static int i=0;
i++;
if (i % 100 == 0) i=0;
name = EACode + i;

long chart_ID=0;
ENUM_OBJECT arrowType;
color warna=clrNONE;
if (orderType == OP_BUY){
arrowType = OBJ_ARROW_UP;
warna = clrBlue;
Print (“Draw Arrow Buy”);
}else if (orderType == OP_SELL){
arrowType = OBJ_ARROW_DOWN;
warna = clrRed;
Print (“Draw Arrow Sell”);
}

if (ObjectFind(name) == -1)
{
ObjectCreate(chart_ID, name, arrowType, 0, x, y);
}

//— set a sign color
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,warna);
////— set a line style (when highlighted)
// ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
////— set a line size (when highlighted)
// ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
////— display in the foreground (false) or background (true)
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,false);
ObjectMove(chart_ID,name, 0, x, y);

}

void OpenOrder(int orderType){
double vol= IN_Vol;

if (orderType >=0){
vol = GetVolume(orderType);
fOrderSend(orderType, vol, 0);
}else{
double hargaBTB = 9999.0;
double hargaSTA = 0.0;
int tOrder;
tOrder = OrdersTotal();
for (int i=tOrder-1; i>=0; i–){
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderMagicNumber() == P_MagicNum){
if ((OrderType() == OP_BUY) && (hargaBTB > OrderOpenPrice())){
hargaBTB = OrderOpenPrice();
}
if ((OrderType() == OP_SELL) && (hargaSTA < OrderOpenPrice())){
hargaSTA = OrderOpenPrice();
}
}
}

int jarak=0;
if (hargaBTB < 9999.0){
jarak = (hargaBTB – Ask) / P_MyPoint;
if (jarak == IN_JarakSameOrder){
vol = GetVolume(OP_BUY);
fOrderSend(OP_BUY, vol, 0);
}
}
if (hargaSTA > 0.0){
jarak = (Bid – hargaSTA) / P_MyPoint;
if (jarak == IN_JarakSameOrder){
vol = GetVolume(OP_SELL);
fOrderSend(OP_SELL, vol, 0);
}
}

}
}

 

//+——————————————————————+
//| SetLabel |
//+——————————————————————+
void SetLabel(string label, string text, int x, int y, color clr, string FontName = “Arial”,int FontSize = 8, int typeCorner = 1)
{
string labelIndicator = EACode + label;
if (ObjectFind(labelIndicator) == -1)
{
ObjectCreate(labelIndicator, OBJ_LABEL, 0, 0, 0);
}

ObjectSet(labelIndicator, OBJPROP_CORNER, typeCorner);
ObjectSet(labelIndicator, OBJPROP_XDISTANCE, x);
ObjectSet(labelIndicator, OBJPROP_YDISTANCE, y);
ObjectSetText(labelIndicator, text, FontSize, FontName, clr);

}

 

//+——————————————————————+
//| SetText |
//+——————————————————————+
void SetText(string txtID, string text, datetime x, double y, color clr=clrWhite, string FontName = “Arial”,int FontSize = 8)
{
//string name = EACode + txtID;
string name = txtID;
if (ObjectFind(name) == -1)
{
ObjectCreate(name, OBJ_TEXT, 0, 0, 0);
}

//— set the text
ObjectSetString(0,name,OBJPROP_TEXT,text);

//— set text font
ObjectSetString(0,name,OBJPROP_FONT,FontName);

//— set font size
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,FontSize);

//Posisi Text
ObjectMove(0,name,0, x, y);

//— set color
ObjectSetInteger(0,name,OBJPROP_COLOR,clr);

////— set the slope angle of the text
// ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
////— set anchor type
// ObjectSetInteger(0,name,OBJPROP_ANCHOR,anchor);

////— display in the foreground (false) or background (true)
// ObjectSetInteger(0,name,OBJPROP_BACK,back);
////— enable (true) or disable (false) the mode of moving the object by mouse
// ObjectSetInteger(0,name,OBJPROP_SELECTABLE,selection);
// ObjectSetInteger(0,name,OBJPROP_SELECTED,selection);
////— hide (true) or display (false) graphical object name in the object list
// ObjectSetInteger(0,name,OBJPROP_HIDDEN,hidden);
////— set the priority for receiving the event of a mouse click in the chart
// ObjectSetInteger(0,name,OBJPROP_ZORDER,z_order);

}

 

//+——————————————————————+
//| ClearObjects function |
//+——————————————————————+
void ClearObjects()
{
for(int i=0;i<ObjectsTotal();i++)
if(StringFind(ObjectName(i),EACode)==0) { ObjectDelete(ObjectName(i)); i–; }
}
//+——————————————————————+

double NormalizeVolume(double vol, int orderType){
int counter = 0;
double termVol=0.0;

if ((orderType != OP_BUY) && (orderType != OP_SELL)){
Print (“FreeMarginCheck not support ordertype ” + orderType);
return vol;
}

if (vol >= 0.01) {
if(AccountFreeMarginCheck(Symbol(),orderType,vol)<=0 || GetLastError()==134){
if ((TimeCurrent() – P_LastAlert) > 1800){
Alert (“Equity: ” + AccountEquity() + ” Current Free Margin : ” + AccountFreeMargin() + “, New Vol: ” + vol + ” Free Margin After Open New Order : ” + AccountFreeMarginCheck(Symbol(),orderType,vol));
P_LastAlert = TimeCurrent();
}
}

while ((counter < 15) && (vol > 0)){
vol = StringToDouble(DoubleToString(vol, 2));
if (AccountFreeMarginCheck(Symbol(),orderType,vol)<=0 || GetLastError()==134){
termVol = vol * 0.9;
//Print (“Volume Order: ” + vol + ” –> New Vol: ” + termVol);
vol = termVol;
if (vol < 0.01) vol = 0;
counter++;
}else break;
}
}else{
vol = 0.0;
}

return vol;
}

 

bool CekJarak(int orderType){
int tOrder;
double harga=0.0;
double selisihJarak;
bool flagJarak = true;
int jarak=0;

jarak = IN_JarakSameOrder;

if (orderType == OP_BUY) harga = Ask;
if (orderType == OP_SELL) harga = Bid;

tOrder = OrdersTotal();
for (int i=tOrder-1; i>=0; i–){
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if ((OrderType() == orderType) && (OrderMagicNumber() == P_MagicNum)){
selisihJarak = (OrderOpenPrice() – harga) / P_MyPoint;
if (selisihJarak < 0) selisihJarak *= -1;
if (selisihJarak < jarak){
flagJarak = false;
break;
}
}
}
return flagJarak;
}

 

double GetVolume(int orderType){
double vol= 0.0;
int tOrder;
int tOrderOnMarket=0;
tOrder = OrdersTotal();
for (int i=tOrder-1; i>=0; i–){
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if ((OrderType() == orderType) && (OrderMagicNumber() == P_MagicNum)){
tOrderOnMarket++;
}
}

int jlhOrder=0;
int idx=0;
for (int i=3; i<15; i++){
jlhOrder += i;
if (tOrderOnMarket <= jlhOrder){
break;
}else idx++;
}

vol = IN_Vol * MathPow(2,idx);

return vol;
}

int fOrderSend(int orderType, double vol, double price, double sl=0.0, double tp=0.0, string comment=””, int MagicNumber=0, color warna=clrNONE, string symbol=””){
int result = 0;
int check;

if (vol <= 0){
Print (“Info: Volume (lot) :” + vol);
return 0;
}

if (MagicNumber == 0) MagicNumber = P_MagicNum;
if (symbol == “” ) symbol = Symbol();

switch (orderType){
case OP_BUY:
price = Ask;
comment += “OP_Buy”;
warna = clrBlue;
//tp = price + (IN_Fix_TP * P_MyPoint);
//sl = price – (IN_Fix_TP * P_MyPoint) – P_Spread;
break;
case OP_BUYLIMIT:
comment += “OP_Buy Limit”;
warna = clrBlue;
break;
case OP_BUYSTOP:
comment += “OP_Buy Stop”;
warna = clrBlue;
break;
case OP_SELL:
price = Bid;
comment += “OP_Sell”;
warna = clrRed;
//tp = price – (IN_Fix_TP * P_MyPoint);
//sl = price + (IN_Fix_TP * P_MyPoint) + P_Spread;
break;
case OP_SELLLIMIT:
comment += “OP_Sell Limit”;
warna = clrRed;
break;
case OP_SELLSTOP:
comment += “OP_Sell Stop”;
warna = clrRed;
break;
}

comment = EACode + ” ” + comment;

if (ExtAllowAutoTrade){
if ((ExtAllowOpBuy == false) && (orderType == OP_BUY)) return 0;
if ((ExtAllowOpSell == false) && (orderType == OP_SELL)) return 0;

bool flagJarak = CekJarak(orderType);

if (orderType < 0){
//OrderType Salah
//Print (__FUNCTION__ + ” Error: Order Type : ” + orderType);
}else if (flagJarak==true){

for (int i=0; i<10; i++){
vol = NormalizeVolume(vol, orderType);
if (vol <= 0){
//Print (“Info NormalizeVolume: Volume (lot) :” + vol);
return 0;
}
result = OrderSend(symbol, orderType, vol, price, P_Slippage, sl, tp, comment, MagicNumber,0, warna);
if (result > 0){
//result = true;
break;
}
Sleep(1000);
RefreshRates();
check=GetLastError();
if(check!=ERR_NO_ERROR) Print(“Error: ” + __FUNCTION__ + ” OrderType: ” + orderType + ” Vol: ” + vol + ” Price: ” + price + ” Error: “,ErrorDescription(check));
}
}
}

return result;
}

bool fOrderModify(int noticket, double sl, double tp, color warna){
bool result = false;
int check;
int selisihWkt;

for (int i=0; i<10; i++){
OrderSelect(noticket, SELECT_BY_TICKET, MODE_TRADES);
//5menit (5 * 60= 360detik)
selisihWkt = TimeCurrent() – OrderOpenTime();
if (selisihWkt >= IN_LamaTunggu_Insta) {
if (OrderModify(OrderTicket(), OrderOpenPrice(), sl, tp, 0, warna)==true){
result = true;
break;
}
check=GetLastError();
if(check!=ERR_NO_ERROR) Print(__FUNCTION__ + “Ticket: ” + noticket + ” sl: ” + sl + ” tp: ” + tp + ” Error: “,ErrorDescription(check));

Sleep(1000);
RefreshRates();
}
}
return result;
}

 

bool fOrderClose(int noTicket, color warna=clrBrown){
//bool fOrderClose(int noticket, datetime orderOpenTime, double lots, int orderType, color warna=clrBrown){
bool result=false;
double harga=0.0;
int selisihWkt;

datetime orderOpenTime=D’1977.09.18′;
double lots=0.0;
int orderType=-1;
OrderSelect (noTicket, SELECT_BY_TICKET, MODE_TRADES);
lots = OrderLots();
orderType = OrderType();
orderOpenTime = OrderOpenTime();

selisihWkt = TimeCurrent() – orderOpenTime;
//5 menit (5 * 60= 300detik)
if (selisihWkt > IN_LamaTunggu_Insta) {
for (int i=0; i<10; i++){
if (orderType == OP_BUY){
harga = Bid;
warna = clrGreen;

}else if (orderType == OP_SELL){
harga = Ask;
warna = clrPink;

}

if (OrderClose(noTicket, lots, harga, P_Slippage, warna)==true){
result = true;
Print (“Order Closed #” + noTicket );
break;
}
Sleep(1000);
RefreshRates();
}
}else{
Print (“Can’t close, less than 5 minutes”);
}

return result;
}

bool fOrderDelete(int noTicketDelete, color warna){
bool result=false;
for (int i=0; i<10; i++){
result = OrderDelete(noTicketDelete);
if (result == true){
//result = true;
break;
}
Sleep(1000);
RefreshRates();
}

return result;
}

void SetTakeProfit(){
int tOrder;
double tProfit=0.0;
double tProfitBuy=0.0, tProfitSell = 0.0;
int tOrderBuy=0, tOrderSell=0;

//+——————————————————————+
//| DATA PROFIT |
//+——————————————————————+

tOrder = OrdersTotal();
for (int i =tOrder-1; i>=0; i–){
bool result = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() == P_MagicNum)

){
tProfit += OrderProfit();
if (OrderType() == OP_BUY) { tProfitBuy += OrderProfit(); tOrderBuy++; }
if (OrderType() == OP_SELL) { tProfitSell += OrderProfit(); tOrderSell++; }

//+——————————————————————+
//| Set Stop Loss |
//+——————————————————————+

if ((OrderStopLoss() == 0) && (IN_StopLoss > 0)){
double sl=0.0;
if (OrderType() == OP_BUY) sl = OrderOpenPrice() – (IN_StopLoss * P_MyPoint) – P_Spread;
if (OrderType() == OP_SELL) sl = OrderOpenPrice() + (IN_StopLoss * P_MyPoint) + P_Spread;
fOrderModify(OrderTicket(), sl, OrderTakeProfit(), clrWhite);
}
}
}

//+——————————————————————+
//| MODE TARGET PROFIT |
//+——————————————————————+
double targetProfit = 0.0;
if (IN_ModeTP == 0){
//Target in PIPS
targetProfit = IN_TargetPips * IN_Vol;
}else if (IN_ModeTP == 1){
//Target in MONEY
targetProfit = IN_TargetMoney;
}

if (IN_KategoriTarget == 0){ //Target BUY dan SELL digabungkan dlm 1 hitungan
//+——————————————————————+
//| BUY DAN SELL PROFIT (GABUNGAN) |
//+——————————————————————+

if ((tOrderBuy+tOrderSell) == 0) tOrderBuy = 1; // jgn nol, nanti hasil perkalian jd nol.

//if ((tProfit >= ((tOrderBuy+tOrderSell) * targetProfit)) && (CekDurasiOpen(1, 99))){
if ((tProfit >= ( targetProfit)) && (CekDurasiOpen(1, 99))){
//faktorVol = 1;
tOrder = OrdersTotal();
for (int i =tOrder-1; i>=0; i–){
bool result = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() == P_MagicNum)

){
if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL)){
fOrderClose(OrderTicket());
}else {
fOrderDelete(OrderTicket(), clrBrown);
}
}
}
//P_HargaBS = 9999.0;
//P_HargaSS = 0.0;
}

} else if (IN_KategoriTarget == 1){ //Target terpisah antara SELL dan BUY

//+——————————————————————+
//| BUY PROFIT |
//+——————————————————————+

if (tOrderBuy == 0) tOrderBuy = 1; //tOrder tidak boleh nol, karena hasil kali akan jadi nol.
//if ((tProfitBuy >= (tOrderBuy * targetProfit)) && (CekDurasiOpen(1, OP_BUY))){
if ((tProfitBuy >= (targetProfit)) && (CekDurasiOpen(1, OP_BUY))){
//faktorVol = 1;
tOrder = OrdersTotal();
for (int i =tOrder-1; i>=0; i–){
bool result = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() == P_MagicNum)
&& ((OrderType() == OP_BUY) || (OrderType() == OP_BUYSTOP))
){
if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL)){
fOrderClose(OrderTicket());
}else {
fOrderDelete(OrderTicket(), clrBrown);
}
}
}
//P_HargaBS = 9999.0;
}

//+——————————————————————+
//| SELL PROFIT |
//+——————————————————————+

if (tOrderSell == 0) tOrderSell = 1; //tOrder tidak boleh nol, karena hasil kali akan jadi nol.
//if ((tProfitSell >= (tOrderSell * targetProfit)) && (CekDurasiOpen(1, OP_SELL))){
if ((tProfitSell >= (targetProfit)) && (CekDurasiOpen(1, OP_SELL))){
//faktorVol = 1;
tOrder = OrdersTotal();
for (int i =tOrder-1; i>=0; i–){
bool result = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() == P_MagicNum)
&& ((OrderType() == OP_SELL) || (OrderType() == OP_SELLSTOP))
){
if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL)){
fOrderClose(OrderTicket());
}else {
fOrderDelete(OrderTicket(), clrBrown);
}
}
}

//P_HargaSS = 0.0;
}

}

}

 

bool CekDurasiOpen(int mode=0, int value=-1){
int selisihWkt;
int tOrder;
bool orderTypeBuy = false;
bool orderTypeSell = false;
bool flagDurasi = false;

if(mode == 0){
//Close by No Tiket, value = no tiket
bool result = OrderSelect(value, SELECT_BY_TICKET, MODE_TRADES);
if (OrderMagicNumber() == P_MagicNum){
selisihWkt = TimeCurrent() – OrderOpenTime();
//Jika MEMENUHI syarat waktu
if (selisihWkt >= IN_LamaTunggu_Insta) {
flagDurasi = true;
}
}
}else if (mode == 1){
//Close by orderType, value = orderType
if (value == OP_BUY) orderTypeBuy = true;
if (value == OP_SELL) orderTypeSell = true;
if (value == 99) { orderTypeBuy = true; orderTypeSell = true; }

tOrder = OrdersTotal();
flagDurasi = true;
for (int i=tOrder-1; i>=0; i–){
bool result = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() == P_MagicNum)
&& (
((OrderType() == OP_BUY) && (orderTypeBuy == true))
|| ((OrderType() == OP_SELL) && (orderTypeSell == true))
)
){
selisihWkt = TimeCurrent() – OrderOpenTime();
//Jika TIDAK memenuhi syarat waktu
if (selisihWkt < IN_LamaTunggu_Insta) {
flagDurasi = false; //ini flag false, karena 1 aja tdk penuhi syarat, batal semua.
break;
}
}

}
}

return flagDurasi;
}

void InfoAccount(){
int x, y;
x = 100;
y = 10;
double profit=0.0;
string balance, equity, floating;
double tProfitBuy=0, tProfitSell=0;
double tVolBuy=0, tVolSell=0;
string floatingBuy, floatingSell;
int tOrderBuy=0, tOrderSell=0;

int tOrderBuyLimit=0, tOrderBuyStop=0;
int tOrderSellLimit=0, tOrderSellStop=0;
//Alert (“>>>>>>>>>> dalam infoaccount”);
int tOrders;
tOrders = OrdersTotal();
for(int i=tOrders-1; i>=0; i–){
OrderSelect(i, SELECT_BY_POS);
//if (OrderMagicNumber() == P_MagicNum) {
if (StringFind(OrderMagicNumber(), P_MagicNum) >= 0){
profit += OrderProfit();
if (OrderType() == OP_BUY){
tProfitBuy += OrderProfit();
tVolBuy += OrderLots();
tOrderBuy++;
}
if (OrderType() == OP_BUYLIMIT) tOrderBuyLimit++;
if (OrderType() == OP_BUYSTOP) tOrderBuyStop++;

if (OrderType() == OP_SELL){
tProfitSell += OrderProfit();
tVolSell += OrderLots();
tOrderSell++;
}
if (OrderType() == OP_SELLLIMIT) tOrderSellLimit++;
if (OrderType() == OP_SELLSTOP) tOrderSellStop++;

}
}

balance = StringFormat(“Balance : %s”, DoubleToString(AccountBalance(), 2));
equity = StringFormat(“Equity : %s”, DoubleToString(AccountEquity(), 2));
floating = StringFormat(“Floating: %s”, DoubleToString(profit, 2));
floatingBuy = StringFormat(“Buy : %s (%s lots) %s orders BL: %s BS: %s”, DoubleToString(tProfitBuy, 2), DoubleToStr(tVolBuy, 2), IntegerToString(tOrderBuy), IntegerToString(tOrderBuyLimit), IntegerToString(tOrderBuyStop));
floatingSell = StringFormat(“Sell : %s (%s lots) %s orders SL: %s SS: %s”, DoubleToString(tProfitSell, 2), DoubleToStr(tVolSell, 2), IntegerToString(tOrderSell), IntegerToString(tOrderSellLimit), IntegerToString(tOrderSellStop));
SetLabel(“lblBalance”, balance, x, y, clrGold);
SetLabel(“lblEquity”, equity, x, y+12, clrGold);
SetLabel(“lblFloating”, floating, x, y+24, clrGold);
SetLabel(“lblFloatingBuy”, floatingBuy, x, y+36, clrGold);
SetLabel(“lblFloatingSell”, floatingSell, x, y+48, clrGold);

//string strTrend;
//if (trend == OP_BUY) {
// strTrend = “Up”;
// SetLabel(“lblTrend”, “Trend : ” + strTrend , x, y+135, clrBlue, “Arial”, 10);
//}
//if (trend == OP_SELL) {
// strTrend = “Down”;
// SetLabel(“lblTrend”, “Trend : ” + strTrend , x, y+135, clrRed, “Arial”, 10);
//}

}

 

 

 

如果你对文件有了解,请帮助投票!

If you are familiar with the file, please help vote!

平均评分 0 / 5. 投票数: 0

到目前为止还没有投票!成为第一位投票人。

相关资源

暂无评论

none
暂无评论...