pseudo code

4 replies

Benjamin Pierce

Subscriber, bbp_participant, customer, community, sq-ultimate, 9 replies.

Visit profile

1 month ago #286064

Is there a guide out there for interpreting pseudo code?

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

1 month ago #286070

Hi,

we have no docs for this. Feel free to ask any questions here about pseudo code

0

Benjamin Pierce

Subscriber, bbp_participant, customer, community, sq-ultimate, 9 replies.

Visit profile

4 weeks ago #286091

Here is a pseudo code for a strategy with only the parameter highest lowest bar opens above highest after opened below.

Can you tell me what the code means?  Thank you!

// Pseudo Source Code of Strategy 0.2
//
//   Generated by StrategyQuant X Build 138 for Tradestation
//   at 03/29/2024 22:14
//
//   Backtested on EURUSD_M1 / D1, 2003.05.05 – 2024.03.08
//   Backtest engine: Tradestation
//——————————————————————–
//——————————————————————–
//  Strategy Parameters
//——————————————————————–
int MagicNumber = 11111;
int BarOpensPeriod1 = 1300;
double StopLossCoef1 = 2.2;
double TrailingStopCoef1 = 6;
double TrailingActCef1 = 6;
Main chart = Current Symbol / Current TF;
//——————————————————————–
// Trading options logic
//——————————————————————–
Don’t Trade On Weekends = false (Friday 0038 – Sunday 0038);
Exit at End Of Day = false (2304);
Exit On Friday = false (2040);
LimitSignalsTimeRange = false (0800 – 1600, Exit at End: false, Orders to close: All);
LimitMaxDistanceFromMarketPrice = false;   //Limit max distance
MaxDistanceFromMarketPct = 6;   //Max distance %
MaxTradesPerDay = 1;
Min SL: 0, Max SL: 0, Min PT: 0, Max PT: 0; // in ticks/pips, 0 means unlimited
//——————————————————————–
// Trading rule: Trading signals (On Bar Open)
//——————————————————————–
LongEntrySignal = (Bar opens above Highest(Main chart, BarOpensPeriod1, PRICE_HIGH) after opened below)[1]
;
ShortEntrySignal = (Bar opens below Lowest(Main chart, BarOpensPeriod1, PRICE_LOW) after opened above)[1]
;
LongExitSignal = false;
ShortExitSignal = false;
//——————————————————————–
// Trading rule: Long entry (On Bar Open)
//——————————————————————–
if LongEntrySignal
{
    // Action #1
    Open Long order at Market;
        Duplicate trades: disabled;
        Stop Loss = StopLossCoef1 * ATR(20);
        Trailing Stop = TrailingStopCoef1 * ATR(20), TS Activation at TrailingActCef1 * ATR(130);
}
//——————————————————————–
// Trading rule: Short entry (On Bar Open)
//——————————————————————–
if (ShortEntrySignal
   and Not LongEntrySignal)
{
    // Action #1
    Open Short order at Market;
        Duplicate trades: disabled;
        Stop Loss = StopLossCoef1 * ATR(20);
        Trailing Stop = TrailingStopCoef1 * ATR(20), TS Activation at TrailingActCef1 * ATR(130);
}
//——————————————————————–
// Trading rule: Long exit (On Bar Open)
//——————————————————————–
if ((LongExitSignal
   and Not LongEntrySignal)
   and (MarketPosition(“Any”, MagicNumber, “”) is Long))
{
    // Action #1
    Close all positions for Symbol = Any and Magic Number = MagicNumber;
}
//——————————————————————–
// Trading rule: Short exit (On Bar Open)
//——————————————————————–
if ((ShortExitSignal
   and Not ShortEntrySignal)
   and (MarketPosition(“Any”, MagicNumber, “”) is Short))
{
    // Action #1
    Close all positions for Symbol = Any and Magic Number = MagicNumber;
}
Broker: No filter

 

0

MontanoLuik

Subscriber, bbp_participant, customer, community, sq-ultimate, 1 replies.

Visit profile

1 week ago #286184

Please don’t take this as the word of an expert and check with other sources, but this is my interpretation.
<h3>General Setup and Parameters</h3>

  • MagicNumber: A unique identifier (11111) for distinguishing trades opened by this strategy from others.
  • BarOpensPeriod1: This is set to 1300, likely representing a period or look-back count for determining trading signals based on price highs and lows.
  • StopLossCoef1, TrailingStopCoef1, TrailingActCef1: These are coefficients used to calculate the stop loss and trailing stop values based on the ATR (Average True Range, a volatility indicator), where ATR(20) and ATR(130) are used.

<h3>Main Chart</h3>

  • The strategy operates on the current symbol and time-frame, which is typically the chart where the strategy is applied.

<h3>Trading Options Logic</h3>

  • Trading Times: It includes settings to control trading times, like not trading on weekends and specifics about when to exit trades (end of day, Fridays, etc.).
  • Limitations on Trading: Includes settings to restrict trading based on time within a day and the maximum distance from the market price at which orders can be placed.
  • Trade Management: It sets limits on the number of trades per day and details the range for setting stop loss (SL) and profit target (PT) values, although these are set to 0, indicating no limit.

<h3>Trading Signals</h3>

  • LongEntrySignal and ShortEntrySignal: These are conditions defined to trigger entry into trades. A long entry occurs when the bar opens above the highest price of the specified period after opening below it in the previous period, and vice versa for a short entry.

<h3>Trading Rules for Entries and Exits</h3>

  • Long Entry: If the LongEntrySignal is true, the strategy will execute a market order to go long. It sets a stop loss and a trailing stop based on the ATR, and specifies conditions for when the trailing stop should activate.
  • Short Entry: Similar to long entry, but for going short. It ensures a short trade is not opened if a long entry signal is also true.
  • Long and Short Exits: These are conditions under which the strategy will close long or short positions, respectively. It checks if an exit signal is true and there’s no corresponding entry signal, and it ensures the trade to be closed matches the specified magic number.

<h3>Miscellaneous</h3>

  • Broker: Indicates that no specific broker filters or settings are applied.

<h3>Summary</h3>
This pseudo-code outlines a strategy that enters long or short positions based on specific conditions related to the opening prices relative to previous highs and lows. It manages trades by setting stop losses and trailing stops based on the ATR, which helps manage risk according to market volatility. The strategy also includes rules for when to trade or not (e.g., not on weekends, specific times of day), and has mechanisms to close positions under defined conditions to secure profits or limit losses.
<h3>VALUES AND SETTINGS</h3>
 
<h3>Strategy Parameters</h3>

  • MagicNumber: 11111
  • BarOpensPeriod1: 1300
  • StopLossCoef1: 2.2
  • TrailingStopCoef1: 6
  • TrailingActCef1: 6
  • Main chart: Current Symbol / Current Time Frame

<h3>Trading Options Logic</h3>

  • Don’t Trade On Weekends: false (From Friday at 00:38 to Sunday at 00:38)
  • Exit at End Of Day: false (Time set at 23:04)
  • Exit On Friday: false (Time set at 20:40)
  • LimitSignalsTimeRange: false (From 08:00 to 16:00, Exit at end: false, Orders to close: All)
  • LimitMaxDistanceFromMarketPrice: false
  • MaxDistanceFromMarketPct: 6%
  • MaxTradesPerDay: 1
  • Minimum Stop Loss: 0, Maximum Stop Loss: 0 (in ticks/pips, 0 means unlimited)
  • Minimum Profit Target: 0, Maximum Profit Target: 0 (in ticks/pips, 0 means unlimited)

<h3>Trading Signals</h3>

  • LongEntrySignal: True if the bar opens above the highest price (high) of the last 1300 bars after previously opening below.
  • ShortEntrySignal: True if the bar opens below the lowest price (low) of the last 1300 bars after previously opening above.

<h3>Trading Rules for Entries and Exits</h3>

  • Long Entry Actions:
    • Open a long order at the market price.
    • Set a stop loss at 2.2 times the ATR(20).
    • Set a trailing stop at 6 times the ATR(20), with activation at 6 times the ATR(130).
  • Short Entry Actions:
    • Open a short order at the market price.
    • Set a stop loss at 2.2 times the ATR(20).
    • Set a trailing stop at 6 times the ATR(20), with activation at 6 times the ATR(130).

<h3>Exit Conditions</h3>

  • Long Exit: Close all long positions if there is a long exit signal and no new long entry signal, for any symbol with the specified MagicNumber.
  • Short Exit: Close all short positions if there is a short exit signal and no new short entry signal, for any symbol with the specified MagicNumber.

1

Benjamin Pierce

Subscriber, bbp_participant, customer, community, sq-ultimate, 9 replies.

Visit profile

1 week ago #286229

Thank you, MontanoLuik!  I appreciate the time you took for this.  I wonder if it’s possible to make this forum searchable so that your answer can be found easily for future users.

0

Viewing 4 replies - 1 through 4 (of 4 total)