Coding a stop order at the last pivot point for stoploss  [SOLVED]

Questions about MultiCharts and user contributed studies.
michael_mio
Posts: 5
Joined: 05 Aug 2021
Has thanked: 5 times

Coding a stop order at the last pivot point for stoploss

Postby michael_mio » 17 Nov 2023

Hello!
I am a programming beginner and I am stuck with coding the following problem.
After opening a trade (e.g. long entry), I would like to place a stop order (for stop loss) at one of the last pivot points (in this case, e.g. at the last or penultimate pivot low). However, it may be that the pivot points are higher than the entry. That's why you have to go back until a deeper pivot point is found. You can see the case in the screenshot. The stop order can only be placed on the green arrow, not on the red arrow.
can someone help me?
Thank you
Best
Michael
Pivot stop loss.jpg
(13.56 KiB) Not downloaded yet

HellGhostEvocatorX
Posts: 81
Joined: 10 Feb 2022
Has thanked: 52 times
Been thanked: 11 times

Re: Coding a stop order at the last pivot point for stoploss

Postby HellGhostEvocatorX » 25 Nov 2023

Unfortunately, I don't know easy language, but if there are lists or arrays in easy language, you could save the pivot points when they occur in an array and then access the previous pivot points accordingly: i.e. Array[0] for the current pivot low point and array [1] for the previous low point. Another approach could be to use series (if that exists). I hope this approach helps you :)

User avatar
ABC
Posts: 721
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 409 times
Contact:

Re: Coding a stop order at the last pivot point for stoploss

Postby ABC » 27 Nov 2023

Hi Michael,

the pivot function has an instance parameter that allows you to look back at prior pivots. From a programming point of view it is however a better approach to store the pivot points as they occur in an array or list as HellGhostEvocatorX has pointed out and use this to look at the prior values when you issue your trade.

Regards,

ABC

michael_mio
Posts: 5
Joined: 05 Aug 2021
Has thanked: 5 times

Re: Coding a stop order at the last pivot point for stoploss  [SOLVED]

Postby michael_mio » 30 Nov 2023

Hello!
Sorry, but as i am a beginner i have problems with the array assignment.
This is my code:

Code: Select all

array: Last_Pivot_Lows[100](0); var: Pivot_count(1); For Pivot_count = 1 to 100 begin Last_Pivot_Lows(Pivot_count) = PivotLowVS(Pivot_count, Low, 3, 3, 30) ; end;

But i receive the error message:
Unknown Function
line 5, column 1
Line 5 is as following:
Last_Pivot_Lows(Pivot_count) = PivotLowVS(Pivot_count, Low, 3, 3, 30) ;

Can someone tell me what the problem is?
Thank you
Michael

User avatar
ABC
Posts: 721
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 409 times
Contact:

Re: Coding a stop order at the last pivot point for stoploss

Postby ABC » 30 Nov 2023

Hi Michael,

the index for the array must be in square brackets and not parenthesis when you try to store or access values in the array.

If you haven't done it, yet, check the free EasyLanguage Essentials PDF that you can find with your search engine of choice. Although written for TS, it is an excellent primer for PowerLanuage, too.

Regards,

ABC

michael_mio
Posts: 5
Joined: 05 Aug 2021
Has thanked: 5 times

Re: Coding a stop order at the last pivot point for stoploss

Postby michael_mio » 30 Nov 2023

Thank you, that was really a stupid mistake :D


Return to “MultiCharts”