Está en la página 1de 15

9/14/2015

'SendingTradingSignalsinaUniversalExpertAdvisorMQL4Articles

Download MetaTrader 5

METATRADER 4 EXAMPLES

SENDING TRADING SIGNALS IN A


UNIVERSAL EXPERT ADVISOR
17 July 2007, 13:41

629
IGOR KIM

Introduction
Some time ago I decided to try to universalize and unitize a process of
developing Expert Advisors in the topic "The Development of a Universal
Expert Advisor". This implied working out a certain standard of developing
main unitbricks, which later could be used to construct Expert Advisors like
frompartsofanconstructionkit.Partlythistaskwasimplemented.Ioffereda
structureofauniversalEAandanideaofauniversaluseofsignalsofdifferent
indicators.InthisarticleIwillcontinuethisworkIwilltrytouniversalizethe
process of forming and sending trading signals and item management in
ExpertAdvisors.InthiscontextanitemmeansanoperationBUYorSELL,all
later discussion will refer to such operations. This article does not describe
pending orders BUYLIMIT, BUYSTOP, SELLLIMIT and SELLSTOP, but at the
endofthearticleIwillshow,thatthismyapproachcanbeeasilyappliedon
them.

ClassificationofTradingSignals
Thereareseveraltypesoftradingsignals:
1.
2.
3.
4.
5.
6.
7.
8.

Buy
Sell
Additionalbuy(averaging)
Additionalsell(averaging)
Fullbuyclose
Fullsellclose
Partialbuyclose
Partialsellclose.

Ifwetransposethedecisionaboutaveragingandpartialclosingfromtheunit
of trading signals formation into the positions and orders management unit,
thislistwillbereducedtothefollowing:
1. Buy
2. Sell
https://www.mql5.com/en/articles/1436

1/15

9/14/2015

'SendingTradingSignalsinaUniversalExpertAdvisorMQL4Articles

3. Closebuy
4. Closesell
5. Donothing(normaloperationofEArequiressuchsignal).
Assumingthis,theoperationschemeofEAshouldbethefollowing:
1. Asignalitemcreatesatradingsignal
2. A trading signal enters the positions management unit, which decides
on new openings, averaging, partial or full closing and sends the
shortened trading signal into the program unit of trading signals
processing
3. The unit of trading signals processing directly performs trading
operations.
InthisarticleIwouldliketodwellondifferentwaysofformingtradingsignals
and ways of their sending to positions management unit, i.e. the interface
betweentheunits,mentionedinpoints1and2.

SwingTradingonOnePosition
Themeaningofsuchtradingisthefollowing:beforeopeninganewposition,
the previous one should be closed. The new position is opposite to the
previousone.Ifitwasbuy,weopensellandviceverse.Inthiscasemoments
ofpositionopeningandclosingconcurintime,thatiswhyclosingsignalscan
be omitted. So the implementation of swing trading requires sending only
threetradingsignals:buy,sellanddonothing.Thesesignalscanbesentusing
oneintvariable.Forexample:
1buy
0donothing
1sell.
Thenthepartofanalysingmarketsituationandcreatingatradingsignalcan
bewritteninaseparatefunction,forexampleGetTradeSignal(),

//+
//|Returnstradingsignal:
//|1buy
//|0donothing
//|1sell
//|Parameters:
//|symnameoftheinstrument(""currentsymbol)
//|tftimeframe(0currenttimeframe)
//+
intGetTradeSignal(stringsym="",inttf=0)
{
intbs=0
if(sym=="")sym=Symbol()

//Blockofanalysisassigningavaluetothevariablebs

return(bs)
}
//+

whichreturnstheabovementionedintegervalues.Activationofthisfunctionis
easiestdonedirectlyinthepositionsmanagementunit.

//+
https://www.mql5.com/en/articles/1436

2/15

9/14/2015

'SendingTradingSignalsinaUniversalExpertAdvisorMQL4Articles

//|Positionsmanagement
//+
voidManagePositions()
{
doublesl=0,tp=0
intbs=GetTradeSignal()

if(bs>0)
{
if(ExistPositions("",OP_SELL))
ClosePositions("",OP_SELL)
if(!ExistPositions("",OP_BUY))
{
if(StopLoss!=0)
sl=AskStopLoss*Point
if(TakeProfit!=0)
tp=Ask+TakeProfit*Point
OpenPosition("",OP_BUY,sl,tp)
}
}
if(bs<0)
{
if(ExistPositions("",OP_BUY))
ClosePositions("",OP_BUY)
if(!ExistPositions("",OP_SELL))
{
if(StopLoss!=0)
sl=Bid+StopLoss*Point
if(TakeProfit!=0)
tp=BidTakeProfit*Point
OpenPosition("",OP_SELL,sl,tp)
}
}
}
//+

In this case a single local variable bs of the integer type acts as a linker
between two program units. The full text of the example source code for
swingtradingbyonepositionislocatedinthefileeSampleSwing.mq4.

SimpleTradingonOnePosition
This case is a little more difficult. Though in the market there is only one
positionateachpointoftime,itsclosingisnotconnectedwiththeopeningof
anotherone.Thatiswhyasuccessfulpositionsmanagementrequiresusingall
five signals: buy, sell, close buy position, close sell position, and do nothing.
They can be sent in one integer type variable with the following values
assigned:
2closesellposition
1buy
0donothing
1sell

https://www.mql5.com/en/articles/1436

3/15

9/14/2015

'SendingTradingSignalsinaUniversalExpertAdvisorMQL4Articles

2closebuyposition.

Positionsmanagementunitcanbewritteninonefunction:

//+
//|Positionsmanagement
//+
voidManagePositions()
{
doublesl=0,tp=0
intbs=GetTradeSignal()

if(ExistPositions())
{
if(bs==2)
ClosePositions("",OP_SELL)
if(bs==2)
ClosePositions("",OP_BUY)
}
else
{
if(bs==1)
{
if(StopLoss!=0)
sl=AskStopLoss*Point
if(TakeProfit!=0)
tp=Ask+TakeProfit*Point
OpenPosition("",OP_BUY,sl,tp)
}
if(bs==1)
{
if(StopLoss!=0)
sl=Bid+StopLoss*Point
if(TakeProfit!=0)
tp=BidTakeProfit*Point
OpenPosition("",OP_SELL,sl,tp)
}
}
}
//+

Thefulltextoftheexamplesourcecodeforsimpletradingbyonepositionis
locatedinthefileeSampleSimple.mq4.
Themaindisadvantageofsendingatradingsignalinonevariableisthatyou
cannot send several signals simultaneously (disadvantages of a serial
interface) for example, you cannot open in both directions, or open with a
simultaneousclosingofanexistingposition,orcloseallpositions.Partiallythis
disadvantagecanbeeliminatedbydividingasignalintotwointegers.
Therearethreewaysofdividingasignal:
1. Open in one variable, close in another one. You can combine opening
and closing, i.e. organize swing trading, but you cannot open in both
directionsorclosecounterdirectionpositions
2. BUY positions (open and close) are in one variable, SELL positions
(open and close) are in another one. You can open positions in both
directionsandcloseallpositionsatonce,butyoucannotsimultaneously
open and close, for example, buy or sell position, i.e. you cannot
reopen
3. OpenBUYandcloseSELLinonevariable,openSELLandcloseBUYin
another.Youcanopeninbothdirectionsandcloseallpositions,butyou
https://www.mql5.com/en/articles/1436

4/15

9/14/2015

'SendingTradingSignalsinaUniversalExpertAdvisorMQL4Articles

cannotorganiseswingtrading.
Letustrytoimplementthesecondvariant,becausereopeningisratherrare.
No one wants to lose money at spread. The second variant can be
implementedinseveralways.
1. Two functions return values into two local variables. One function creates
signalsforbuying,thesecondoneforselling.

//+
//|Returnstradingsignalforlongpositions:
//|1buy
//|0donothing
//|1closeBUY
//|Parameters:
//|symnameoftheinstrument(""currentsymbol)
//|tftimeframe(0currenttimeframe)
//+
intGetTradeSignalBuy(stringsym="",inttf=0)
{
intbs=0
if(sym=="")
sym=Symbol()

//Blockofanalysisassigningavaluetothevariablebs

return(bs)
}

//+
//|Returnstradingsignalforshortpositions:
//|1sell
//|0donothing
//|1closeSELL
//|Parameters:
//|symnameoftheinstrument(""currentsymbol)
//|tftimeframe(0currenttimeframe
//+
intGetTradeSignalSell(stringsym="",inttf=0)
{
intbs=0
if(sym=="")
sym=Symbol()

//Blockofanalysisassigningavaluetothevariablebs

return(bs)
}

//+
//|Positionsmanagement
//+
voidManagePositions()
{
doublesl=0,tp=0
intbs=GetTradeSignalBuy()
intss=GetTradeSignalSell()

if(ExistPositions())
{
if(bs<0)
ClosePositions("",OP_BUY)
if(ss<0)
ClosePositions("",OP_SELL)
}
if(!ExistPositions())
{
if(bs>0)
https://www.mql5.com/en/articles/1436

5/15

9/14/2015

'SendingTradingSignalsinaUniversalExpertAdvisorMQL4Articles

{
if(StopLoss!=0)
sl=AskStopLoss*Point
if(TakeProfit!=0)
tp=Ask+TakeProfit*Point
OpenPosition("",OP_BUY,sl,tp)
}
if(ss>0)
{
if(StopLoss!=0)
sl=Bid+StopLoss*Point
if(TakeProfit!=0)
tp=BidTakeProfit*Point
OpenPosition("",OP_SELL,sl,tp)
}
}
}
//+

Thisisasimpleandconvenientwaytocreateandsendatradingsignal,buta
signal unit is divided into two functions which would probably slow down its
operation.

2.Twoglobalvariablesacquirevaluesinonefunction.

//+
BuySignal=0
SellSignal=0

//+
//|Createstradingsignals.
//|Parameters:
//|symnameoftheinstrument(""currentsymbol)
//|tftimeframe(0currenttimeframe)
//+
voidFormTradeSignals(stringsym="",inttf=0)
{
if(sym=="")sym=Symbol()

//BlockofanalysisassigningavaluetothevariableBuySigna
}

//+
//|Positionsmanagement
//+
voidManagePositions()
{
doublesl=0,tp=0

FormTradeSignals()
if(ExistPositions())
{
if(BuySignal<0)
ClosePositions("",OP_BUY)
if(SellSignal<0)
ClosePositions("",OP_SELL)
}
if(!ExistPositions())
{
if(BuySignal>0)
{
if(StopLoss!=0)
sl=AskStopLoss*Point
if(TakeProfit!=0)
tp=Ask+TakeProfit*Point
https://www.mql5.com/en/articles/1436

6/15

9/14/2015

'SendingTradingSignalsinaUniversalExpertAdvisorMQL4Articles

OpenPosition("",OP_BUY,sl,tp)
}
if(SellSignal>0)
{
if(StopLoss!=0)
sl=Bid+StopLoss*Point
if(TakeProfit!=0)
tp=BidTakeProfit*Point
OpenPosition("",OP_SELL,sl,tp)
}
}
}
//+

Itisclearfromthissourcecode,thatrealizationwithglobalvariablesdoesnot
differmuchfromthefirstmethod.Theapparentadvantageisthatthesignal
modeisinonefunction.

3.Twolocalvariablesarepassedbyreferencetoonefunction.

//+
//|Returnstradingsignals.
//|Parameters:
//|bsBUYsignal
//|ssSELLsignal
//|symnameoftheinstrument(""currentsymbol)
//|tftimeframe(0currenttimeframe)
//+
voidGetTradeSignals(int&bs,int&ss,stringsym="",inttf=
{
if(sym=="")
sym=Symbol()

//Blockofanalysisassigningavaluetovariablesbsandss
}

//+
//|Positionsmanagement
//+
voidManagePositions()
{
doublesl=0,tp=0
intbs=0,ss=0

GetTradeSignals(bs,ss)
if(ExistPositions())
{
if(bs<0)
ClosePositions("",OP_BUY)
if(ss<0)
ClosePositions("",OP_SELL)
}
if(!ExistPositions())
{
if(bs>0)
{
if(StopLoss!=0)
sl=AskStopLoss*Point
if(TakeProfit!=0)
tp=Ask+TakeProfit*Point
OpenPosition("",OP_BUY,sl,tp)
}
if(ss>0)
{
if(StopLoss!=0)
https://www.mql5.com/en/articles/1436

7/15

9/14/2015

'SendingTradingSignalsinaUniversalExpertAdvisorMQL4Articles

sl=Bid+StopLoss*Point
if(TakeProfit!=0)
tp=BidTakeProfit*Point
OpenPosition("",OP_SELL,sl,tp)
}
}
}
//+

4.Anarrayoftwoelements.Ifitisglobal,itisinitializedinsidethefunction.If
itislocal,itispassedbyreference.Everythingiseasyhereonearrayinstead
of two variables. Global elements and local elements by reference were
discussedearlier.Nothingnew.
And, finally, we can organize a fullvalued parallel interface sending trading
signals, dividing it into four variables. For positions management each signal
hastwostates:existsornot.Thatiswhyweshouldbetterdealwithvariables
of logical type. You can combine signals, sending them using four variables,
limitless.Hereisanexampleofacodewithanarrayoffourelementsoflogical
type.

//+
//|Returnstradingsignals.
//|Parameters:
//|msarrayofsignals
//|symnameoftheinstrument(""currentsymbol)
//|tftimeframe(0currenttimeframe)
//+
voidGetTradeSignals(bool&ms[],stringsym="",inttf=0)
{
if(sym=="")
sym=Symbol()

//Blockofanalysisfillingmsarray:
//ms[0]=True//Buy
//ms[1]=True//Sell
//ms[2]=True//CloseBuy
//ms[3]=True//CloseSell
}

//+
//|Positionsmanagement
//+
voidManagePositions()
{
boolms[4]={False,False,False,False}
doublesl=0,tp=0

GetTradeSignals(ms)
if(ExistPositions())
{
if(ms[2])
ClosePositions("",OP_BUY)
if(ms[3])
ClosePositions("",OP_SELL)
}
if(!ExistPositions())
{
if(ms[0])
{
if(StopLoss!=0)
sl=AskStopLoss*Point
https://www.mql5.com/en/articles/1436

8/15

9/14/2015

'SendingTradingSignalsinaUniversalExpertAdvisorMQL4Articles

if(TakeProfit!=0)
tp=Ask+TakeProfit*Point
OpenPosition("",OP_BUY,sl,tp)
}
if(ms[1])
{
if(StopLoss!=0)
sl=Bid+StopLoss*Point
if(TakeProfit!=0)
tp=BidTakeProfit*Point
OpenPosition("",OP_SELL,sl,tp)
}
}
}
//+

Implementationwithlocalvariables,passedbyreferencetoonefunction,and
with global variables, initialized inside one function, should not cause any
problems.However,initializationoffourlocalvariablesbyvalues,returnedby
fourdifferentfunctions,ishardlyreasonable.

SupportingtheMainPosition
When a signal comes, one position is opened. It becomes the main position.
All other signal entries against the main position are ignored. Additional
positionsareopenedonsignals,correspondingwiththemainposition.Atthe
closingofthemainposition,alladditionalpositionsarealsoclosed.
Sendingtradingsignalsforthistacticscanbeimplementedusingone,twoor
four variables. All this was described earlier. The difficulty, you can meet, is
providingtheconnection:onesignaloneposition.Incaseoftradingonone
position this question was solved by a simple check of the position existence
using the function ExistPositions(). If there is a position, entrance signal is
omitted,nopositionentrancesignalisperformed.
So,therearedifferentwaysout:
1. Providingapausebetweenentrances.Theeasiestrealization
2. One bar one entrance. A variety of the first way. The realization is
alsoeasy
3. Numerating signals and controlling arrays of signals and tickets of
orders. This is the most difficult implementation with a doubtful
reliability.
Thisistheexampleofacodeforthefirstmethod:

//+
externintPauseBetweenEntrys=3600//Pausebetweenentrancesi

//+
//|Positionsmanagement
//+
voidManagePositions()
{
boolms[4]={False,False,False,False}
doublesl=0,tp=0

GetTradeSignals(ms)
if(ExistPositions())
{
if(ms[2])
https://www.mql5.com/en/articles/1436

9/15

9/14/2015

'SendingTradingSignalsinaUniversalExpertAdvisorMQL4Articles

ClosePositions("",OP_BUY)
if(ms[3])
ClosePositions("",OP_SELL)
}
if(SecondsAfterOpenLastPos()>=PauseBetweenEntrys)
{
if(ms[0])
{
if(StopLoss!=0)
sl=AskStopLoss*Point
if(TakeProfit!=0)
tp=Ask+TakeProfit*Point
OpenPosition("",OP_BUY,sl,tp)
}
if(ms[1])
{
if(StopLoss!=0)
sl=Bid+StopLoss*Point
if(TakeProfit!=0)
tp=BidTakeProfit*Point
OpenPosition("",OP_SELL,sl,tp)
}
}
}

//+
//|Returnsnumberofsecondsafterthelastpositionisopened.
//|Parameters:
//|symnameoftheinstrument(""currentsymbol)
//|opoperation(1anyposition)
//|mnMagicNumber(1anymagicnumber)
//+
datetimeSecondsAfterOpenLastPos(stringsym="",intop=1,int
{
datetimeoot
inti,k=OrdersTotal()

if(sym=="")sym=Symbol()
for(i=0iki++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==sym)
{
if(OrderType()==OP_BUY||OrderType()==OP_SELL
{
if(op0||OrderType()==op)
{
if(mn0||OrderMagicNumber()==mn)
{
if(ootOrderOpenTime())
oot=OrderOpenTime()
}
}
}
}
}
}
return(CurTime()oot)
}
//+

The full text of the example source code for the tactics with supporting the
mainpositionislocatedinthefileeSampleMain.mq4.

SwingTradingwithAveraging
https://www.mql5.com/en/articles/1436

10/15

9/14/2015

'SendingTradingSignalsinaUniversalExpertAdvisorMQL4Articles

Whenanentrancesignalcomes,onepositionisopened.Basedonallfurther
signals in the direction of the first position, new additional positions are
opened. When a signal comes against the existing positions, all positions are
closed and one position is opened in the direction of the signal. The trading
signalisrepeated.
Sendingandexecutionoftradingsignalsforswingtradingononepositionhas
beendiscussed.Letusadaptthisexampletoimplementtheoptionofopening
additionalpositions.Toprovidetheconnectiononesignaloneposition,letus
usetherestrictionofentrancepossibilitybyatimeperiodofonebar.Onebar
oneentrance.

//+
//|Positionsmanagement
//+
voidManagePositions()
{
doublesl=0,tp=0
intbs=GetTradeSignal()

if(bs>0)
{
if(ExistPositions("",OP_SELL))
ClosePositions("",OP_SELL)
if(NumberOfBarLastPos()>0)
{
if(StopLoss!=0)
sl=AskStopLoss*Point
if(TakeProfit!=0)
tp=Ask+TakeProfit*Point
OpenPosition("",OP_BUY,sl,tp)
}
}
if(bs<0)
{
if(ExistPositions("",OP_BUY))
ClosePositions("",OP_BUY)
if(NumberOfBarLastPos()>0)
{
if(StopLoss!=0)
sl=Bid+StopLoss*Point
if(TakeProfit!=0)
tp=BidTakeProfit*Point
OpenPosition("",OP_SELL,sl,tp)
}
}
}

//+
//|Returnsthebarnumberofthelastpositionopeningor1.
//|Parameters:
//|symnameoftheinstrument(""currentsymbol)
//|tftimeframe(0currenttimeframe)
//|opoperation(1anyposition)
//|mnMagicNumber(1anymagicnumber)
//+
intNumberOfBarLastPos(stringsym="",inttf=0,intop=1,int
{
datetimeoot
inti,k=OrdersTotal()

if(sym=="")
sym=Symbol()
for(i=0iki++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
https://www.mql5.com/en/articles/1436

11/15

9/14/2015

'SendingTradingSignalsinaUniversalExpertAdvisorMQL4Articles

if(OrderSymbol()==sym)
{
if(OrderType()==OP_BUY||OrderType()==OP_SELL
{
if(op0||OrderType()==op)
{
if(mn0||OrderMagicNumber()==mn)
{
if(ootOrderOpenTime())oot=OrderOpenTim
}
}
}
}
}
}
return(iBarShift(sym,tf,oot,True))
}
//+

The full text of the example source code for swing trading with averaging is
locatedinthefileeSampleSwingAdd.mq4.

PortfolioTactics
For each trading signal one position is opened and supported irrespective of
others.
Atfirstsightthisisthemostcomplicatedvariantoftradingsignalsexecutionin
terms of software implementation. Here except sending trading signals, you
needtosendthebelongingofasignaltooneportfoliooranother.Butifyou
divide the signals into groups, which constitute a portfolio, you will see, that
each separate group is a simple oneposition trading. The way of combining
groupsintoaportfolioisevident:assignauniquenumbertoeachgroupand
setasearchofallgroupsinacycle.Hereisanexampleoffoursignalgroups:

//+
//|Returnstradingsignals.
//|Parameters:
//|msarrayofsignals
//|nsnumberofasignal
//|symnameoftheinstrument(""currentsymbol)
//|tftimeframe(0currenttimeframe)
//+
voidGetTradeSignals(bool&ms[],intns,stringsym="",inttf
{
if(sym=="")sym=Symbol()

//Switchingsignalgroupsusingoperatorsswitchorif
//Blockofanalysisfulfillingthearrayms:
//ms[0]=True//Buy
//ms[1]=True//Sell
//ms[2]=True//CloseBuy
//ms[3]=True//CloseSell
}

//+
//|Positionsmanagement
//+
voidManagePositions()
{
boolms[4]
doublesl=0,tp=0
inti

https://www.mql5.com/en/articles/1436

12/15

9/14/2015

'SendingTradingSignalsinaUniversalExpertAdvisorMQL4Articles

for(i=0i4i++)
{
ArrayInitialize(ms,False)
GetTradeSignals(ms,i)
if(ExistPositions("",1,MAGIC+i))
{
if(ms[2])ClosePositions("",OP_BUY,MAGIC+i)
if(ms[3])ClosePositions("",OP_SELL,MAGIC+i)
}
if(!ExistPositions("",1,MAGIC+i))
{
if(ms[0])
{
if(StopLoss!=0)
sl=AskStopLoss*Point
if(TakeProfit!=0)
tp=Ask+TakeProfit*Point
OpenPosition("",OP_BUY,sl,tp,MAGIC+i)
}
if(ms[1])
{
if(StopLoss!=0)
sl=Bid+StopLoss*Point
if(TakeProfit!=0)
tp=BidTakeProfit*Point
OpenPosition("",OP_SELL,sl,tp,MAGIC+i)
}
}
}
}
//+

Thefulltextoftheexamplesourcecodeforprofiletacticsislocatedinthefile
eSampleCase.mq4.

TradingSignalsforOrders
Let us view the list of trading signals, necessary for working with pending
orders.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.

SetBuyLimit
SetSellLimit
SetBuyStop
SetSellStop
DeleteBuyLimit
DeleteSellLimit
DeleteBuyStop
DeleteSellStop
ModifyBuyLimit
ModifySellLimit
ModifyBuyStop
ModifySellStop.

You can easily guess that with pending orders you could want to send
simultaneouslyfourormoretradingsignals.AndwhatiftheEAlogicrequires
workingbothwithpositionsandorders?
Hereistheextendedfulllistofalltradingsignals.
1. OpenBuy
2. OpenSell
3. SetBuyLimit
https://www.mql5.com/en/articles/1436

13/15

9/14/2015

'SendingTradingSignalsinaUniversalExpertAdvisorMQL4Articles

4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.

SetSellLimit
SetBuyStop
SetSellStop
CloseBuy
CloseSell
DeleteBuyLimit
DeleteSellLimit
DeleteBuyStop
DeleteSellStop
ModifyBuyLimit
ModifySellLimit
ModifyBuyStop
ModifySellStop.

Sixteentradingsignals!Twobytes!Therewasalsoanideatosendsignalsasa
binary number, but in a string. For example, 00101..., where the position of
zerooronewouldbeinchargeofadefinitesignal.Buttherewouldbealotof
fuss with substrings and decoding of signals. So, you see, that the most
convenient way out is an array with the number of elements, equal to the
number of signals. Besides, for better convenience of reference to the array
elements, indexes can be defined as constants. MQL4 already contains
OP_BUY,OP_SELLandsoon.Wecaneasilycontinue:
#defineOP_CLOSEBUY6
#defineOP_CLOSESELL7
#defineOP_DELETEBUYLIMIT8
#defineOP_DELETESELLLIMIT9
#defineOP_DELETEBUYSTOP10
#defineOP_DELETESELLSTOP11
#defineOP_MODIFYBUYLIMIT12
#defineOP_MODIFYSELLLIMIT13
#defineOP_MODIFYBUYSTOP14
#defineOP_MODIFYSELLSTOP15

and refer to the array elements: ms[OP_BUY] or ms[OP_MODIFYSELLLIMIT]


insteadofms[0]andms[13].Still,thisisthematteroftaste.Ipreferconcise
andsimplecodes,thatiswhyIchoosefigures.
Letuscontinue.Everythingseemseasyandnice!Butwealsoneedpricelevels
of setting orders, stops and takeprofit levels for positions, because each
tradingsignalcanbeartheinformationaboutacertainstopandtakeprofitand
acertainpricelevelofsettinganorder.Buthowcanwepassthisinformation
togetherwithatradingsignal?Iofferthefollowingwayout:
1. Declare a twodimensional array with a number of lines equal to the
numberofsignals,andthreecolumns
2. Thefirstcolumnwillpointbythezerovalueattheabsenceofasignal,
by the nonzero value at the existence of a signal for a position (a
pricelevelofsettinganorder)
3. Thesecondcolumnstops
4. Thethirdcolumntakeprofitlevels.
Thefulltextoftheexamplesourcecodefortradingwithordersislocatedin
thefileeSampleOrders.mq4.
Andwhat,ifweneedtosetseveralBuyLimitorseveralSellStop?Andtoopen
positions?Inthiscasewewilldoasdescribedinthepart"PortfolioTactics"of
this article, i.e. use a profile tactics with position and order identification by
magicnumbers.

Conclusion
https://www.mql5.com/en/articles/1436

14/15

9/14/2015

'SendingTradingSignalsinaUniversalExpertAdvisorMQL4Articles

Itistimetosumeverythingup:
1. Sending signals using one variable has some disadvantage of a serial
interfaceonlyonesignalcanbesentateachpointoftime
2. Implementing a parallel interface leads to the larger number of
variables and complicates their management, but allows sending
simultaneouslydozensofsignals.
So, using one or another method of sending trading signals must be
determinedbyexpediency.
TranslatedfromRussianbyMetaQuotesSoftwareCorp.
Originalarticle:http://articles.mql4.com/ru/articles/1436
TranslatedfromRussianbyMetaQuotesSoftwareCorp.
Originalarticle:https://www.mql5.com/ru/articles/1436

Attachedfiles|
DownloadZIP
bPositions.mqh (20.13KB)
eSampleCase.mq4 (7.12KB)
eSampleMain.mq4 (7.94KB)
eSampleOrders.mq4 (14.71KB)
eSampleSimple.mq4 (6.88KB)
eSampleSwing.mq4 (6.8KB)
eSampleSwingAdd.mq4 (8.01KB)
Warning:AllrightstothesematerialsarereservedbyMQL5Ltd.Copyingorreprintingofthesematerialsinwholeor

JoinusdownloadMetaTrader5!

Windows

iPhone/iPad

MacOS

Android

Linux

MQL5StrategyLanguage|SourceCodeLibrary|HowtoWriteanExpertAdvisororanIndicator|Order
DevelopmentofExpertAdvisor
DownloadMetaTrader5|MetaTrader5TradePlatform|ApplicationStore|MQL5CloudNetwork
About|WebsiteHistory|TermsandConditions|PrivacyPolicy|Contacts
Copyright20002015,MQL5Ltd.

https://www.mql5.com/en/articles/1436

15/15