Orders Execution
Miscellaneous
0
Views
0
Downloads
0
Favorites
Crashprofits
//+------------------------------------------------------------------+
//| 145-1603161641.mq4 |
//| Copyright © 2016, mindful FX UG |
//| ce@mindfulfx.de; www.mindfulfx.de |
//| Programmierer-Initialen: AS, CE |
//+------------------------------------------------------------------+
#property description "Crashprofit EA"
#property description "Systematik von Emanuel Baltensperger"
#property description "mindful FX Projektnr. 145-1603161641"
#property copyright "Systematik von Emanuel Baltensperger, Code von mindful FX, www.mindfulfx.de, ea@mindfulfx.de"
#property version "1.0" // 29.04.2016
//====================================================================
#property strict
enum TYPES
{
Down=-1, // Down
Up=1, // Up
};
extern string Einstellungen_order = "-----------------------------------------------";
input TYPES TypeOrder = Down; //ProfitRichtung
extern int MagicNumber = 1603161641; // Magicnummer
extern double LotSize = 1; // BaseLot
extern string Einstellungen_open_exit = "Orders ----> Eingabe in Pips/Punkte & Sekunden";
extern int stopLoss = 7; // StopLoss
extern int LiveORderStopLossMove = 20; // ZeitStopLossMove
extern string Einstellungen_exit = "PendingOrders ----> Eingabe in Pips/Punkte & Sekunden";
extern int pendingBuyRange = 50; // PendingBuyRange
extern int pendingSellRange = 50; // PendingSellRange
extern int OrderORderStopLossMoveBuyStop = 20; // ZeitPendingBuyMove
extern int OrderORderStopLossMoveSellStop = 20; // ZeitPendingSellMove
extern string Einstellungen_zusatz = "ZusaetzlicheOrders ----> Eingabe in Pips";
extern double LotSizeZ = 1.0; // LotsZusatzdeal
extern int MagicNumberZ = 1603161642; //MagicnummerZusatzdeal
extern int trailingStopLoss = 50; //TrailingSL Zusatzdeal
extern string Einstellungen_alarm = "Alarm an/aus";
extern bool AlarmOn = false; // AlarmAn
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
double point;int Q;
int digits;
string NotesFont = "Cambria";
int NotesLocation_x = 10;
int NotesLocation_y = 10;
int TaillePolice = 12;
int BuyStopAlt,SellStopAlt;
color NotesColor = Black;
datetime tModify ;
datetime t2Modify;
int OnInit()
{
tModify = -1;
t2Modify = -1;
//---
/////////////////////////////////////////////
if (Digits >= 4)
{
point = 0.0001;
digits = 4;
}
if (Digits == 2 || Digits == 3)
{
point = 0.01;
digits = 2;
}
if (Digits == 1 || Digits == 0)
{
point = 1;
digits = 0;
}
/////////////////////////////////////////////
//---
/////////////////////////////////////////////
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
/**************************/
if ( AccountingBuyOrder(MagicNumber) == 0 && AccountingSellOrder(MagicNumber) == 0 )
{
/////////////////////
if ( TypeOrder == Down )
{
BuyOrder2(MagicNumber,stopLoss);
SellOrder(MagicNumber);
}
//////////////////////
if ( TypeOrder == Up )
{
BuyOrder(MagicNumber);
SellOrder2(MagicNumber,stopLoss);
}
}
/**************************/
if ( TypeOrder == Down && AccountingBuyOrder(MagicNumber) == 0 && AccountingSellOrder(MagicNumber) == 1 && AccountingBuyStop(MagicNumber) == 0)
{
BuyStop( NormalizeDouble(MarketInfo(Symbol(),MODE_ASK) + (pendingBuyRange * point),Digits),LotSize,MagicNumber,0);
BuyStopAlt=1;
}
if ( TypeOrder == Up && AccountingBuyOrder(MagicNumber) == 1 && AccountingSellOrder(MagicNumber) == 0 && AccountingSellStop(MagicNumber) == 0)
{
SellStop( NormalizeDouble(MarketInfo(Symbol(),MODE_BID) - (pendingSellRange * point),Digits),LotSize,MagicNumber,0);
SellStopAlt=1;
}
/**************************/
if ( TypeOrder == Down && AccountingBuyOrder(MagicNumber) == 0 && AccountingSellOrder(MagicNumber) == 1 && AccountingBuyStop(MagicNumber) == 1 && ( t2Modify == - 1 || (TimeCurrent() - t2Modify) >= OrderORderStopLossMoveBuyStop ) )
{
double p1 = NormalizeDouble(MarketInfo(Symbol(),MODE_ASK) + (pendingBuyRange * point),Digits);
modifyOrder(MagicNumber,OP_BUYSTOP,p1, 0 /*(p1 - (stopLoss * point))*/);
t2Modify = TimeCurrent();
BuyStopAlt=1;
}
if ( TypeOrder == Up && AccountingBuyOrder(MagicNumber) == 1 && AccountingSellOrder(MagicNumber) == 0 && AccountingSellStop(MagicNumber) == 1 && ( t2Modify == - 1 || (TimeCurrent() - t2Modify) >= OrderORderStopLossMoveSellStop ) )
{
double p2 = NormalizeDouble(MarketInfo(Symbol(),MODE_BID) - (pendingSellRange * point),Digits);
modifyOrder(MagicNumber,OP_SELLSTOP,p2, 0 /*(p2 + (stopLoss * point))*/);
t2Modify = TimeCurrent();
SellStopAlt=1;
}
/**************************/
if(LotSizeZ<=0){SellStopAlt=0;BuyStopAlt=0;}
if ( AccountingBuyOrder(MagicNumber) == 1 && AccountingSellOrder(MagicNumber) == 1 )
{
int bo3=-1;
if(TypeOrder==Down&&BuyStopAlt==1&&AccountingBuyOrder(MagicNumberZ)==0)bo3=BuyOrder3(MagicNumberZ,trailingStopLoss,LotSizeZ);
if(bo3>0)BuyStopAlt=0;
int so3=-1;
if(TypeOrder==Up&&SellStopAlt==1&&AccountingSellOrder(MagicNumberZ)==0)so3=SellOrder3(MagicNumberZ,trailingStopLoss,LotSizeZ);
if(so3>0)SellStopAlt=0;
}
if(AccountingBuyOrder(MagicNumberZ)+AccountingSellOrder(MagicNumberZ)>0) RegularTrailingStop();
else MoveTrailingStop();
//---
//DrawChartNote();
}
//+------------------------------------------------------------------+
/************ Account Buy Stop ***********/
int AccountingBuyStop(int mgc)
{
int i;
int BuyStop = 0;
for( i=0; i<OrdersTotal(); i++) // Loop through orders
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES )) continue;
{
if ( OrderMagicNumber() == mgc && OrderType() == OP_BUYSTOP && OrderSymbol()==Symbol())
BuyStop++; // Number of sell order
}
}
return BuyStop;
}
/************ Account Buy Stop ***********/
int AccountingSellStop(int mgc)
{
int i;
int SellStop = 0;
for( i=0; i<OrdersTotal(); i++) // Loop through orders
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES )) continue;
{
if ( OrderMagicNumber() == mgc && OrderType() == OP_SELLSTOP && OrderSymbol()==Symbol())
SellStop++; // Number of sell order
}
}
return SellStop;
}
/************ Account Buy Order ***********/
int AccountingBuyOrder(int mgc)
{
int i;
int BuyStop = 0;
for( i=0; i<OrdersTotal(); i++) // Loop through orders
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES )) continue;
{
if ( OrderMagicNumber() == mgc && OrderType() == OP_BUY && OrderSymbol()==Symbol())
BuyStop++; // Number of sell order
}
}
return BuyStop;
}
/************ Account Sell Order ***********/
int AccountingSellOrder(int mgc)
{
int i;
int SellStop = 0;
for( i=0; i<OrdersTotal(); i++) // Loop through orders
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES )) continue;
{
if ( OrderMagicNumber() == mgc && OrderType() == OP_SELL && OrderSymbol()==Symbol())
SellStop++; // Number of sell order
}
}
return SellStop;
}
/********************************************/
bool RectLabelCreate(const long chart_ID, // chart's ID
const string name, // label name
const int sub_window, // subwindow index
const int x, // X coordinate
const int y, // Y coordinate
const int width, // width
const int height, // height
const color back_clr, // background color
const ENUM_BORDER_TYPE border, // border type
const ENUM_BASE_CORNER corner, // chart corner for anchoring
const color clr, // flat border color (Flat)
const ENUM_LINE_STYLE style, // flat border style
const int line_width, // flat border width
const bool back, // in the background
const bool selection, // highlight to move
const bool hidden, // hidden in the object list
const long z_order) // priority for mouse click
{
//--- reset the error value
ResetLastError();
ObjectDelete(name);
//--- create a rectangle label
if(!ObjectCreate(chart_ID,name,OBJ_RECTANGLE_LABEL,sub_window,0,0))
{
Print(__FUNCTION__,
": failed to create a rectangle label! Error code = ",GetLastError());
return(false);
}
//--- set label coordinates
ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- set label size
ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
//--- set background color
ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);
//--- set border type
ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_TYPE,border);
//--- set the chart's corner, relative to which point coordinates are defined
ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- set flat border color (in Flat mode)
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set flat border line style
ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- set flat border width
ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,line_width);
//--- display in the foreground (false) or background (true)
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the label by mouse
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object list
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
return(true);
}
/************ Chart note system *********************/
void draw_obj(string obj,string text,int size,color clr,int cor,int x,int y,string font)
{
//----
ObjectDelete(obj);
ObjectCreate(obj,OBJ_LABEL,0,0,0);
ObjectSetText(obj,text,size,font,clr);
ObjectSet(obj,OBJPROP_CORNER,cor);
ObjectSet(obj,OBJPROP_XDISTANCE,x);
ObjectSet(obj,OBJPROP_YDISTANCE,y);
}
/*
void DrawChartNote()
{
draw_obj("CP","Copyright 2016,mindful FX !",TaillePolice,clrGoldenrod,4,NotesLocation_x,NotesLocation_y,NotesFont);
}
*/
/********************************************* Trailling Stop function feature **************************************************************/
void MoveTrailingStop()
{
bool oky ;
int cnt,total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
oky = OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)
{
if(OrderType()==OP_BUY && ( tModify == -1 || (TimeCurrent() - tModify) >= LiveORderStopLossMove) && OrderStopLoss() != NormalizeDouble( MarketInfo(Symbol(),MODE_BID) - (stopLoss*point),Digits) && TypeOrder == Down )
{
oky = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble( MarketInfo(Symbol(),MODE_BID) - (stopLoss*point),Digits),OrderTakeProfit(),0,Blue);
tModify = TimeCurrent();
}
if(OrderType()== OP_SELL && ( tModify == -1 || (TimeCurrent() - tModify) >= LiveORderStopLossMove) && OrderStopLoss() != NormalizeDouble(MarketInfo(Symbol(),MODE_ASK) + (stopLoss*point) ,Digits) && TypeOrder == Up )
{
oky = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(MarketInfo(Symbol(),MODE_ASK) + (stopLoss*point) ,Digits),OrderTakeProfit(),0,Red);
tModify = TimeCurrent();
}
if(
(OrderType()==OP_BUY && OrderStopLoss()>0 && TypeOrder == Up)
||(OrderType()==OP_SELL && OrderStopLoss()>0 && TypeOrder == Down)
)
{
oky = OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderTakeProfit(),0,clrDarkSlateGray);
}
}
}
}
/*****************************************************/
void RegularTrailingStop()
{
bool oky ;
int cnt,total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
oky = OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumberZ)
{
if(OrderType()==OP_BUY && OrderStopLoss() < NormalizeDouble( MarketInfo(Symbol(),MODE_BID) - (trailingStopLoss*point),Digits) )
{
oky = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble( MarketInfo(Symbol(),MODE_BID) - (trailingStopLoss*point),Digits),OrderTakeProfit(),0,clrChartreuse);
}
if(OrderType()== OP_SELL && OrderStopLoss() > NormalizeDouble(MarketInfo(Symbol(),MODE_ASK) + (trailingStopLoss*point) ,Digits) )
{
oky = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(MarketInfo(Symbol(),MODE_ASK) + (trailingStopLoss*point) ,Digits),OrderTakeProfit(),0,clrFireBrick);
}
}
}
}
/***********************************/
double GetIndicatorVlaue(int Buffer,int Shift)
{
double val = 0;
//val = iCustom(NULL,0,"Data Transfer",,Buffer,Shift);
return(val);
// Buffer 1 => Up Trend
// Buffer 2 => Down Trend
}
/*************************************/
int BuyOrder(int mgc)
{
int ticket_buy;
for (int j=0; (j<50) && IsTradeContextBusy(); j++) // Checking if server busy
Sleep(100);
RefreshRates();
double TakeProfitLevel = 0;
double StoplossLevel = 0;
TakeProfitLevel = 0;
StoplossLevel = 0;
/***********************************************/
ticket_buy = OrderSend(Symbol(), OP_BUY, LotSize, Ask, 300, StoplossLevel, TakeProfitLevel, "Buy Order", mgc, 0, DodgerBlue);
// sending order to broker server
return(ticket_buy);
}
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
int SellOrder(int mgc)
{
int ticket_sell;
for (int j=0; (j<50) && IsTradeContextBusy(); j++) // Checking if server busy
Sleep(100);
RefreshRates();
double TakeProfitLevel = 0;
double StoplossLevel = 0 ;
TakeProfitLevel = 0;
StoplossLevel =0;
ticket_sell = OrderSend(Symbol(), OP_SELL, LotSize , Bid, 300, StoplossLevel, TakeProfitLevel, "Sell Order", mgc, 0, DeepPink);
return(ticket_sell);
}
/******************************/
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
void CloseAllBuyOrder(int mgc)
{
bool result;
double price = 0;
int cmd,error;
//----
int total = OrdersTotal();
for(int cnt=0;cnt<total;cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
{
cmd=OrderType();
//---- first order is buy or sell
if(cmd==OP_BUY && ( OrderSymbol()== Symbol() && OrderMagicNumber() == mgc && OrderType() == OP_BUY) )
{
while(true)
{
RefreshRates();
if(cmd==OP_BUY) price=MarketInfo(OrderSymbol(),MODE_BID);
{
result=OrderClose(OrderTicket(),OrderLots(),price,3,CLR_NONE);
}
if(result!=TRUE) { error=GetLastError(); Print("LastError = ",error); }
else
{
error=0;
cnt = cnt -1;
}
if(error==135) RefreshRates();
else break;
}
}
}
else Print( "Error when order select ", GetLastError());
}
}
/********** Close Sell order *******************************/
void CloseAllSellOrder(int mgc)
{
bool result;
double price = 0;
int cmd,error;
//----
int total = OrdersTotal();
for(int cnt=0;cnt<total;cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
{
cmd=OrderType();
//---- first order is buy or sell
if(cmd==OP_SELL && ( OrderSymbol()== Symbol() && OrderMagicNumber() == mgc && OrderType() == OP_SELL) )
{
while(true)
{
RefreshRates();
if(cmd==OP_SELL) price=MarketInfo(OrderSymbol(),MODE_ASK);
{
result=OrderClose(OrderTicket(),OrderLots(),price,3,CLR_NONE);
}
if(result!=TRUE) { error=GetLastError(); Print("LastError = ",error); }
else
{
error=0;
cnt = cnt -1;
}
if(error==135) RefreshRates();
else break;
}
}
}
else Print( "Error when order select ", GetLastError());
}
}
/************* Waitting Bar To Close ***********/
bool NewBarBuy()
{
static datetime dt = 0;
if (dt != Time[0])
{
dt = Time[0]; Sleep(100); // wait for tick
return(true);
}
return(false);
}
bool NewBarSell()
{
static datetime dt = 0;
if (dt != Time[0])
{
dt = Time[0]; Sleep(100); // wait for tick
return(true);
}
return(false);
}
/*********************************/
/*************************************/
int BuyOrder2(int mgc,int stp)
{
int ticket_buy;
for (int j=0; (j<50) && IsTradeContextBusy(); j++) // Checking if server busy
Sleep(100);
RefreshRates();
double TakeProfitLevel = 0;
double StoplossLevel = 0;
TakeProfitLevel = 0;
StoplossLevel = Bid - (stp * point);
/***********************************************/
ticket_buy = OrderSend(Symbol(), OP_BUY, LotSize, Ask, 300, StoplossLevel, TakeProfitLevel, "Buy Order", mgc, 0, DodgerBlue);
// sending order to broker server
return(ticket_buy);
}
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
int SellOrder2(int mgc,int stp)
{
int ticket_sell;
for (int j=0; (j<50) && IsTradeContextBusy(); j++) // Checking if server busy
Sleep(100);
RefreshRates();
double TakeProfitLevel = 0;
double StoplossLevel = 0 ;
TakeProfitLevel = 0;
StoplossLevel = Ask + (stp * point);
ticket_sell = OrderSend(Symbol(), OP_SELL, LotSize , Bid, 300, StoplossLevel, TakeProfitLevel, "Sell Order", mgc, 0, DeepPink);
return(ticket_sell);
}
/*************************************/
int BuyOrder3(int mgc,int stp, double lts)
{
int ticket_buy;
for (int j=0; (j<50) && IsTradeContextBusy(); j++) // Checking if server busy
Sleep(100);
RefreshRates();
double TakeProfitLevel = 0;
double StoplossLevel = 0;
TakeProfitLevel = 0;
StoplossLevel = Bid - (stp * point);
/***********************************************/
if(lts>0)ticket_buy = OrderSend(Symbol(), OP_BUY, lts, Ask, 300, StoplossLevel, TakeProfitLevel, "Buy Order Zusatzdeal", mgc, 0, clrChartreuse);
else ticket_buy=-1;
// sending order to broker server
return(ticket_buy);
}
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
int SellOrder3(int mgc,int stp, double lts)
{
int ticket_sell;
for (int j=0; (j<50) && IsTradeContextBusy(); j++) // Checking if server busy
Sleep(100);
RefreshRates();
double TakeProfitLevel = 0;
double StoplossLevel = 0 ;
TakeProfitLevel = 0;
StoplossLevel = Ask + (stp * point);
if(lts>0)ticket_sell = OrderSend(Symbol(), OP_SELL, lts , Bid, 300, StoplossLevel, TakeProfitLevel, "Sell Order Zusatzdeal", mgc, 0, clrFireBrick);
else ticket_sell=-1;
return(ticket_sell);
}
/******************************/
int BuyStop(double price,double lot,int mgc,int stp)
{
int ticket_BuyStop;
/////////////////////////////////////////////////////////////////
double TakeProfitLevel=0;
double StoplossLevel=0;
//////////////////////////////////////////////////////////////////
TakeProfitLevel=0;
if(stp>0)StoplossLevel= price - (stp * point);
else StoplossLevel=0;
//***************************************************************************/
for(int j=0;(j<50) && IsTradeContextBusy(); j++) // Checking if server busy
Sleep(100);
RefreshRates();
/*******************************************************************************/
ticket_BuyStop=OrderSend(Symbol(),OP_BUYSTOP,lot,price,50,StoplossLevel,TakeProfitLevel,"Buy Stop",mgc,0,DeepPink);
if ( ticket_BuyStop > 0 ) if (AlarmOn == true ) Alert("Orderauslösung "+Symbol());
return(ticket_BuyStop);
}
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
int SellStop(double price,double lot,int mgc,int stp)
{
int ticket_sellStop;
/////////////////////////////////////////////////////////////////
double TakeProfitLevel=0;
double StoplossLevel=0;
/*****************************************************************/
TakeProfitLevel= 0;
if(stp>0)StoplossLevel = price + (stp * point);
else StoplossLevel=0;
/*************************************************************/
//***************************************************************************/
for(int j=0;(j<50) && IsTradeContextBusy(); j++) // Checking if server busy
Sleep(100);
RefreshRates();
/*******************************************************************************/
ticket_sellStop=OrderSend(Symbol(),OP_SELLSTOP,lot,price,50,StoplossLevel,TakeProfitLevel,"Sell Stop",mgc,0,DeepPink);
if ( ticket_sellStop > 0 ) if (AlarmOn == true ) Alert("Orderauslösung "+Symbol());
return(ticket_sellStop);
}
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH//
void modifyOrder(int mgc,int ordetype,double price,double stoploss)
{
bool oky = false;
int i;
int BuyStop = 0;
for( i=0; i<OrdersTotal(); i++) // Loop through orders
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES )) continue;
{
if ( OrderMagicNumber() == mgc && OrderType() == ordetype && OrderSymbol()==Symbol() && OrderOpenPrice() != price)
{
if((ordetype==OP_BUYSTOP&&price<OrderOpenPrice())||(ordetype==OP_SELLSTOP&&price>OrderOpenPrice()))
oky = OrderModify(OrderTicket(),price,stoploss,OrderTakeProfit(),0,clrNONE);
}
}
}
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---