Back to Strategies

Example Strategy

Code Strategy by 0x7s0lt1·2026-03-09


// Example Code strategy 🤘

if($.Strategy.lastTrigger.action === $.Action.EXIT){

    // logic for opening a position
    if($.Price.price < 1250){
        await $.Strategy.action($.Action.LONG);
    }

}
else{

    // logic for closing a position
    const roiPercent = $.Strategy.roi(true);

    // take profit
    if(roiPercent >= 1.5){
        await $.Strategy.action($.Action.EXIT);
    }
    // stop loss
    else if(roiPercent <= -1.5){
        await $.Strategy.action($.Action.EXIT);
    }

}


// get and set storage data
const storage = await $.Storage.get();

if(!storage){

    // get thirdparty data
    const response = await $.Http.get("https://jsonplaceholder.typicode.com/todos/1");

    if(response.status === 200){
        const data = JSON.parse(response.text);
        await $.Storage.set(data);
    }

}