Help with Expert

Locked
arkan1976
Trader
Posts: 10
Joined: Wed Sep 26, 2012 3:27 pm

Help with Expert

Post by arkan1976 »

hello, It is possible to modify this code to Buy_TP and Sell_TP be equal to the opening price of the current candle?
Thanks.

Code: Select all

//+------------------------------------------------------------------+
//| [EA]Go2SamePoint.mq4 |
//| Copyright 2009, Viking234.Com. |
//| http://www.viking234.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2009, Viking234.Com."
#property link "http://www.viking234.com"

// http://www.forexfactory.com/showthread.php?p=2997450
// 4Shared file is WORKING VERSION!
// Distributed under GPL (http://www.gnu.org/licenses/gpl.txt)
// Donation? Very Welcome > http://www.viking234.com side bar. =)

extern double Buy_TP=1.3000; //Here be open price current candle
extern double Buy_SL=0;
extern double Sell_TP=1.3000; //Here be open price current candle
extern double Sell_SL=0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int HowDeepIsYourLove = OrdersTotal();
double TP,SL;
for(int z=0;z<HowDeepIsYourLove;z++) {
if(OrderSelect(z,SELECT_BY_POS,MODE_TRADES)) {
if(OrderType()==OP_BUY||OrderType()==OP_BUYSTOP||OrderType()==OP_BUYLIMIT) {
TP=NormalizeDouble(Buy_TP,Digits);
SL=NormalizeDouble(Buy_SL,Digits);
if(OrderTakeProfit()!=TP||OrderStopLoss()!=SL) {
if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,CLR_NONE))
Print("Something happened in BuyHood =), error#"+GetLastError());
}
} else if(OrderType()==OP_SELL||OrderType()==OP_SELLSTOP||OrderType()==OP_SELLLIMIT) {
TP=NormalizeDouble(Sell_TP,Digits);
SL=NormalizeDouble(Sell_SL,Digits);
if(OrderTakeProfit()!=TP||OrderStopLoss()!=SL) {
if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,CLR_NONE))
Print("Something happened in SellHood =), error#"+GetLastError());
}
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

Help with Expert

Post by milanese »

arkan1976 » Sat Oct 01, 2016 5:52 pm wrote:hello, It is possible to modify this code to Buy_TP and Sell_TP be equal to the opening price of the current candle?
Thanks.

Code: Select all

//+------------------------------------------------------------------+
//| [EA]Go2SamePoint.mq4 |
//| Copyright 2009, Viking234.Com. |
//| http://www.viking234.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2009, Viking234.Com."
#property link "http://www.viking234.com"

// http://www.forexfactory.com/showthread.php?p=2997450
// 4Shared file is WORKING VERSION!
// Distributed under GPL (http://www.gnu.org/licenses/gpl.txt)
// Donation? Very Welcome > http://www.viking234.com side bar. =)

extern double Buy_TP=1.3000; //Here be open price current candle
extern double Buy_SL=0;
extern double Sell_TP=1.3000; //Here be open price current candle
extern double Sell_SL=0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int HowDeepIsYourLove = OrdersTotal();
double TP,SL;
for(int z=0;z<HowDeepIsYourLove;z++) {
if(OrderSelect(z,SELECT_BY_POS,MODE_TRADES)) {
if(OrderType()==OP_BUY||OrderType()==OP_BUYSTOP||OrderType()==OP_BUYLIMIT) {
TP=NormalizeDouble(Buy_TP,Digits);
SL=NormalizeDouble(Buy_SL,Digits);
if(OrderTakeProfit()!=TP||OrderStopLoss()!=SL) {
if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,CLR_NONE))
Print("Something happened in BuyHood =), error#"+GetLastError());
}
} else if(OrderType()==OP_SELL||OrderType()==OP_SELLSTOP||OrderType()==OP_SELLLIMIT) {
TP=NormalizeDouble(Sell_TP,Digits);
SL=NormalizeDouble(Sell_SL,Digits);
if(OrderTakeProfit()!=TP||OrderStopLoss()!=SL) {
if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,CLR_NONE))
Print("Something happened in SellHood =), error#"+GetLastError());
}
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Believe me this code is so much outdated that it would be wasting time to modify it..
To avoid to irritate other member I have this thread locked.

Cheers :)

Tommaso
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
Locked

Return to “Coders Hangout”