Stop loss and Take Profit....Code

Questions about MultiCharts and user contributed studies.
shivax
Posts: 90
Joined: 02 Sep 2013
Has thanked: 37 times

Stop loss and Take Profit....Code

Postby shivax » 19 Sep 2017

i'm Long to signal...

I want to fixed Stop loss (in price) and Take Profit (in price)

if (MarketPosition=1) then begin
sell next bar (entryprice(0)-averagetruerange(ran)/portionSL) stop; //stop loss

but i now i set take profit.....it hide the stop loss..

how i set Stop Loss and Take Profit togeter? thanks

can give me a link of example to signal...

User avatar
Anna MultiCharts
Posts: 560
Joined: 14 Jul 2017
Has thanked: 42 times
Been thanked: 140 times

Re: Stop loss and Take Profit....Code

Postby Anna MultiCharts » 21 Sep 2017

Hello, shivax!

Please, try to use the pre-built Stop Loss and Profit Target signals as part of your strategy or refer to their script as reference. You can view a study’s script by clicking on the “Open Script” button in the Format Objects window or by double-clicking on a study in the Navigator section in PowerLanguage Editor.

shivax
Posts: 90
Joined: 02 Sep 2013
Has thanked: 37 times

Re: Stop loss and Take Profit....Code

Postby shivax » 22 Sep 2017

I see you example but i don't want to take profit and stop with Amount...

I want to use stop loss and profit target if the price goes below or above a certain level

I can write :


if (MarketPosition=1) then begin
sell next bar (entryprice(0)-averagetruerange(ran)/portionSL) stop; //stop loss

But if i want also to code the exit Profit....how i can i code it? ( i want code Profit And Target togheter)

User avatar
Anna MultiCharts
Posts: 560
Joined: 14 Jul 2017
Has thanked: 42 times
Been thanked: 140 times

Re: Stop loss and Take Profit....Code

Postby Anna MultiCharts » 22 Sep 2017

shivax,

it is possible to set both commands in the strategy’s code. You can try using such keywords as SetStopLoss_pt and SetProfitTarget_pt that will allow specifying the difference from the current price in ticks, not dollars. For more information, please, refer to the following pages:
https://www.multicharts.com/trading-sof ... tTarget_pt
https://www.multicharts.com/trading-sof ... topLoss_pt

To code an exit Profit you can try to modify the code you gave as example: change stop to limit and minus to plus.
Please, specify what you understand under “Profit And Target togheter”.

shivax
Posts: 90
Joined: 02 Sep 2013
Has thanked: 37 times

Re: Stop loss and Take Profit....Code

Postby shivax » 22 Sep 2017

Please, specify what you understand under “Profit And Target togheter”.

I mean set stop loss and set profit in the same time....

another question :
If i want to exit to end of bar, i want to code it...what i write in my script? I have to generate order intrabar or not?
Thank you

User avatar
Anna MultiCharts
Posts: 560
Joined: 14 Jul 2017
Has thanked: 42 times
Been thanked: 140 times

Re: Stop loss and Take Profit....Code

Postby Anna MultiCharts » 25 Sep 2017

Shivax,

Please, try to use Sell and BuyToCover commands for market or price orders depending on your needs. If you need an order to be placed straight after the generation, please, use IOG. To place an order on the bar close – don’t use IOG.
Please, refer to these links for more info:
https://www.multicharts.com/trading-sof ... egy_Orders
https://www.multicharts.com/trading-sof ... Generation

MAZINGUER
Posts: 75
Joined: 06 Jan 2017
Has thanked: 9 times
Been thanked: 25 times

Re: Stop loss and Take Profit....Code

Postby MAZINGUER » 25 Sep 2017

Hello shivax,
maybe you mean something like that

If marketposition=1 then begin
sell nex bar at ....... stop; // StopLoss
sell next bar at...... limit; // take profit
end;

Same using marketposition=-1 but using the Word buytocover


Return to “MultiCharts”