Trade Simulation Scripted Exit

A forum for EdgeRater users to discuss and share ideas around Trade Simulation.

Moderator: Chris White

Post Reply
bsegura
Posts: 32
Joined: Tue Jan 12, 2021 11:56 am

Trade Simulation Scripted Exit

Post by bsegura »

Hello:

Could you please tell me how to use a script exit in the Trade Simulation. I would like to exit 5% above the price of my triggered entry
-Thanks
Chris White
Posts: 212
Joined: Mon Nov 29, 2010 9:21 pm

Re: Trade Simulation Scripted Exit

Post by Chris White »

Generally, scripts that generate single 'events' are independent of each other such that a script you use to generate an exit event is not aware of the script that was used to generate the entry event. Therefore the exit script does not know what the entry price was.

There are a couple of solutions:

1. Use the exit rules section of the Trade Simulation tab. This tab knits together entry events and exit events and provides settings for things like profit and loss stops. So, you could have a fixed % gain as a profit stop:
profit-stop.png
profit-stop.png (40.97 KiB) Viewed 1861 times

2. It's possible to write a script that creates both entry and exit events and then use the 'scripted entries and exits' setting in the trade simulation tab. You would use this if the available trade simulation settings do not meet your specific needs. Here's an example of a completely scripted entry and exit:

Here’s an example using PSAR with a scripted stop based on the entry price:

// Method using Scripted Entry and exit rules
P:= PSAR(0.02, 0.2);

// Entry Event is the Bull PSAR Flip
EntryEvent: CROSS(C, P);

// Entry price is the Close price on the entry bar
EntryPrice: VALUEWHEN(C, EntryEvent);

// Regular Exit event is the BEAR PSAR flip
RegularExitEvent: CROSS(P, C);

// Regular Exit price is the close price on the Exit bar
RegularExitPrice: VALUEWHEN(C, RegularExitEvent);

// Stop Exit Event is if Close Price < Entry Price
StopExitEvent: C < EntryPrice;

// Stop Exit price is the Close of the Stop event bar
StopPrice: VALUEWHEN(C, StopExitEvent);

// Actual Exit event is either regular exit OR Stop exit
ActualExitEvent: RegularExitEvent| StopExitEvent;

// Actual Exit Price is either Regular exit price or stop exit price
ActualExitPrice: IF(StopExitEvent, StopPrice, RegularExitPrice);

// Assign each of the lines to a trade simulation attribute
// Then you can run this script to generate entries AND exits
// And choosed 'Use Scripted Entry and Exit rules
@SETATTR(EntryEvent, 'LongEntryEvent');
@SETATTR(EntryPrice, 'LongEntryPrice');
@SETATTR(ActualExitEvent, 'LongExitEvent');
@SETATTR(ActualExitPrice, 'LongExitPrice');
Post Reply